Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions tests/phpstan/HookDocBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,7 @@ public function getReferencedHookDocsHash(): string {
// depend on where the checkout lives.
$key = $this->getRootRelativePath( $target );

if ( ! isset( $docs[ $key ] ) ) {
$docs[ $key ] = $this->getHookDocs( $target );
}
$docs[ $key ] ??= $this->getHookDocs( $target );
}
}

Expand Down Expand Up @@ -562,9 +560,7 @@ private function findHookDoc( string $file, array $matcher ): ?string {
* @return HookDocs
*/
private function getHookDocs( string $file ): array {
if ( ! isset( $this->fileHookDocs[ $file ] ) ) {
$this->fileHookDocs[ $file ] = self::loadHookDocs( $file );
}
$this->fileHookDocs[ $file ] ??= self::loadHookDocs( $file );

return $this->fileHookDocs[ $file ];
}
Expand Down Expand Up @@ -663,9 +659,7 @@ private static function parseHookDocs( string $code ): array {
$name_expr = $args[0]->value;

if ( $name_expr instanceof String_ ) {
if ( ! isset( $docs['exact'][ $name_expr->value ] ) ) {
$docs['exact'][ $name_expr->value ] = $doc->getText();
}
$docs['exact'][ $name_expr->value ] ??= $doc->getText();
continue;
}

Expand Down
4 changes: 1 addition & 3 deletions tests/phpunit/includes/abstract-testcase.php
Original file line number Diff line number Diff line change
Expand Up @@ -1406,9 +1406,7 @@ public function go_to( $url ) {
} else {
$req = $url;
}
if ( ! isset( $parts['query'] ) ) {
$parts['query'] = '';
}
$parts['query'] ??= '';

$_SERVER['REQUEST_URI'] = $req;
unset( $_SERVER['PATH_INFO'] );
Expand Down
4 changes: 1 addition & 3 deletions tests/phpunit/includes/class-wp-phpunit-timing-metrics.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,7 @@ public static function from_file( $file, $testcase_callback = null ) {
throw new RuntimeException( 'The JUnit timing report contains no testcases.' );
}

if ( null === $suite_time ) {
$suite_time = array_sum( $test_times );
}
$suite_time ??= array_sum( $test_times );

sort( $test_times, SORT_NUMERIC );

Expand Down
12 changes: 3 additions & 9 deletions tests/phpunit/includes/class-wp-test-stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ private function open( $url ) {
throw new Exception( 'Cannot use an empty bucket name' );
}

if ( ! isset( WP_Test_Stream::$data[ $this->bucket ] ) ) {
WP_Test_Stream::$data[ $this->bucket ] = array();
}
WP_Test_Stream::$data[ $this->bucket ] ??= array();

$this->data_ref =& WP_Test_Stream::$data[ $this->bucket ][ $this->file ];

Expand Down Expand Up @@ -101,9 +99,7 @@ public function stream_read( $count ) {
* @see streamWrapper::stream_write
*/
public function stream_write( $data ) {
if ( ! isset( $this->data_ref ) ) {
$this->data_ref = '';
}
$this->data_ref ??= '';

$left = substr( $this->data_ref, 0, $this->position );
$right = substr( $this->data_ref, $this->position + strlen( $data ) );
Expand Down Expand Up @@ -186,9 +182,7 @@ public function stream_eof() {
public function stream_metadata( $path, $option, $value ) {
$this->open( $path );
if ( STREAM_META_TOUCH === $option ) {
if ( ! isset( $this->data_ref ) ) {
$this->data_ref = '';
}
$this->data_ref ??= '';
return true;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ abstract public function update_object( $object_id, $fields );
* @return int|WP_Error The object ID on success, WP_Error object on failure.
*/
public function create( $args = array(), $generation_definitions = null ) {
if ( is_null( $generation_definitions ) ) {
$generation_definitions = $this->default_generation_definitions;
}
$generation_definitions ??= $this->default_generation_definitions;

$generated_args = $this->generate_args( $args, $generation_definitions, $callbacks );
$object_id = $this->create_object( $generated_args );
Expand Down Expand Up @@ -155,10 +153,8 @@ public function create_many( $count, $args = array(), $generation_definitions =
* @return array|WP_Error Combined array on success. WP_Error when default value is incorrect.
*/
public function generate_args( $args = array(), $generation_definitions = null, &$callbacks = null ) {
$callbacks = array();
if ( is_null( $generation_definitions ) ) {
$generation_definitions = $this->default_generation_definitions;
}
$callbacks = array();
$generation_definitions ??= $this->default_generation_definitions;

// Use the same incrementor for all fields belonging to this object.
$gen = new WP_UnitTest_Generator_Sequence();
Expand Down
12 changes: 4 additions & 8 deletions tests/phpunit/includes/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,8 @@ public function current_filter() {
if ( is_callable( 'current_filter' ) ) {
$current_filter = current_filter();
} else {
$current_filter = array_key_last( $wp_actions );
if ( null === $current_filter ) {
$current_filter = false;
}
$current_filter = array_key_last( $wp_actions );
$current_filter ??= false;
}

return $current_filter;
Expand Down Expand Up @@ -393,10 +391,8 @@ public function start_handler( $parser, $name, $attributes ) {
public function data_handler( $parser, $data ) {
$index = count( $this->data ) - 1;

if ( ! isset( $this->data[ $index ]['content'] ) ) {
$this->data[ $index ]['content'] = '';
}
$this->data[ $index ]['content'] .= $data;
$this->data[ $index ]['content'] ??= '';
$this->data[ $index ]['content'] .= $data;
}

public function end_handler( $parser, $name ) {
Expand Down
12 changes: 3 additions & 9 deletions tests/phpunit/tests/admin/plugin-dependencies/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,7 @@ private function reset_static_properties() {
* @param mixed $value The new value.
*/
public function set_property_value( $property, $value ) {
if ( ! isset( self::$reflected_members[ $property ] ) ) {
self::$reflected_members[ $property ] = new ReflectionProperty( self::$instance, $property );
}
self::$reflected_members[ $property ] ??= new ReflectionProperty( self::$instance, $property );

if ( PHP_VERSION_ID < 80100 ) {
self::$reflected_members[ $property ]->setAccessible( true );
Expand All @@ -112,9 +110,7 @@ public function set_property_value( $property, $value ) {
* @return mixed The value of the property.
*/
public function get_property_value( $property ) {
if ( ! isset( self::$reflected_members[ $property ] ) ) {
self::$reflected_members[ $property ] = new ReflectionProperty( self::$instance, $property );
}
self::$reflected_members[ $property ] ??= new ReflectionProperty( self::$instance, $property );

if ( PHP_VERSION_ID < 80100 ) {
self::$reflected_members[ $property ]->setAccessible( true );
Expand All @@ -136,9 +132,7 @@ public function get_property_value( $property ) {
* @return mixed The result of the method call.
*/
protected function call_method( $method, ...$args ) {
if ( ! isset( self::$reflected_members[ $method ] ) ) {
self::$reflected_members[ $method ] = new ReflectionMethod( self::$instance, $method );
}
self::$reflected_members[ $method ] ??= new ReflectionMethod( self::$instance, $method );

if ( PHP_VERSION_ID < 80100 ) {
self::$reflected_members[ $method ]->setAccessible( true );
Expand Down
10 changes: 3 additions & 7 deletions tests/phpunit/tests/blocks/register.php
Original file line number Diff line number Diff line change
Expand Up @@ -721,13 +721,9 @@ public function test_register_block_style_handle_uses_correct_core_stylesheet( $
$block_name = str_replace( 'core/', '', $metadata['name'] );

// Normalize metadata similar to `register_block_type_from_metadata()`.
$metadata['file'] = wp_normalize_path( realpath( $metadata_file ) );
if ( ! isset( $metadata['style'] ) ) {
$metadata['style'] = "wp-block-$block_name";
}
if ( ! isset( $metadata['editorStyle'] ) ) {
$metadata['editorStyle'] = "wp-block-{$block_name}-editor";
}
$metadata['file'] = wp_normalize_path( realpath( $metadata_file ) );
$metadata['style'] ??= "wp-block-$block_name";
$metadata['editorStyle'] ??= "wp-block-{$block_name}-editor";

// Ensure block assets are separately registered.
add_filter( 'should_load_separate_core_block_assets', '__return_true' );
Expand Down
8 changes: 2 additions & 6 deletions tests/phpunit/tests/blocks/registerCoreBlockStyleHandles.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,8 @@ private function get_block_data() {

$data = array();
foreach ( $core_blocks_meta as $name => $schema ) {
if ( ! isset( $schema['style'] ) ) {
$schema['style'] = "wp-block-$name";
}
if ( ! isset( $schema['editorStyle'] ) ) {
$schema['editorStyle'] = "wp-block-{$name}-editor";
}
$schema['style'] ??= "wp-block-$name";
$schema['editorStyle'] ??= "wp-block-{$name}-editor";

$data[ $name ] = $schema;
}
Expand Down
20 changes: 8 additions & 12 deletions tests/phpunit/tests/fonts/font-face/wp-font-face-tests-dataset.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,12 +386,10 @@ public static function get_custom_font_families( $key = '' ) {
),
);

if ( null === $data ) {
$data = array(
'input' => $custom_theme_json_fonts,
'expected' => $expected_font_faces,
);
}
$data ??= array(
'input' => $custom_theme_json_fonts,
'expected' => $expected_font_faces,
);

return $data[ $key ] ?? $data;
}
Expand Down Expand Up @@ -473,12 +471,10 @@ public static function get_custom_style_variations( $key = '' ) {
@font-face{font-family:"DM Sans";font-style:italic;font-weight:500;font-display:fallback;src:url('{$uri}dm-sans/DMSans-Medium-Italic.woff2') format('woff2');font-stretch:normal;}
CSS;

if ( null === $data ) {
$data = array(
'expected' => $expected_font_families,
'expected_styles' => $expected_styles,
);
}
$data ??= array(
'expected' => $expected_font_families,
'expected_styles' => $expected_styles,
);

return $data[ $key ] ?? $data;
}
Expand Down
18 changes: 7 additions & 11 deletions tests/phpunit/tests/rest-api/rest-schema-validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -1697,18 +1697,14 @@ public function data_unique_items() {
continue;
}
// type is required for our implementation
if ( ! isset( $suite['schema']['type'] ) ) {
$suite['schema']['type'] = 'array';
}
$suite['schema']['type'] ??= 'array';
// items is required for our implementation
if ( ! isset( $suite['schema']['items'] ) ) {
$suite['schema']['items'] = array(
'type' => $all_types,
'items' => array(
'type' => $all_types,
),
);
}
$suite['schema']['items'] ??= array(
'type' => $all_types,
'items' => array(
'type' => $all_types,
),
);
foreach ( $suite['tests'] as $test ) {
$tests[] = array( $test, $suite );
}
Expand Down
26 changes: 9 additions & 17 deletions tests/phpunit/tests/url.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,11 +364,9 @@ public function test_get_adjacent_post() {
$post_id = self::factory()->post->create( array( 'post_date' => gmdate( 'Y-m-d H:i:s', $now - 1 ) ) );
$post_id2 = self::factory()->post->create( array( 'post_date' => gmdate( 'Y-m-d H:i:s', $now ) ) );

if ( ! isset( $GLOBALS['post'] ) ) {
$GLOBALS['post'] = null;
}
$orig_post = $GLOBALS['post'];
$GLOBALS['post'] = get_post( $post_id2 );
$GLOBALS['post'] ??= null;
$orig_post = $GLOBALS['post'];
$GLOBALS['post'] = get_post( $post_id2 );

$p = get_adjacent_post();
$this->assertInstanceOf( 'WP_Post', $p );
Expand Down Expand Up @@ -416,10 +414,8 @@ public function test_get_adjacent_post_should_return_private_posts_belonging_to_
)
);

if ( ! isset( $GLOBALS['post'] ) ) {
$GLOBALS['post'] = null;
}
$orig_post = $GLOBALS['post'];
$GLOBALS['post'] ??= null;
$orig_post = $GLOBALS['post'];

$GLOBALS['post'] = get_post( $p2 );

Expand Down Expand Up @@ -456,10 +452,8 @@ public function test_get_adjacent_post_should_return_private_posts_belonging_to_
)
);

if ( ! isset( $GLOBALS['post'] ) ) {
$GLOBALS['post'] = null;
}
$orig_post = $GLOBALS['post'];
$GLOBALS['post'] ??= null;
$orig_post = $GLOBALS['post'];

$GLOBALS['post'] = get_post( $p2 );

Expand Down Expand Up @@ -502,10 +496,8 @@ public function test_get_adjacent_post_should_not_return_private_posts_belonging
)
);

if ( ! isset( $GLOBALS['post'] ) ) {
$GLOBALS['post'] = null;
}
$orig_post = $GLOBALS['post'];
$GLOBALS['post'] ??= null;
$orig_post = $GLOBALS['post'];

$GLOBALS['post'] = get_post( $p3 );

Expand Down
4 changes: 1 addition & 3 deletions tests/phpunit/tests/wp-token-map/wpTokenMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,7 @@ private function get_html5_test_dataset() {
private static function get_html5_token_map() {
static $html5_token_map = null;

if ( ! isset( $html5_token_map ) ) {
$html5_token_map = WP_Token_Map::from_array( self::get_test_input_array( 'HTML5' ) );
}
$html5_token_map ??= WP_Token_Map::from_array( self::get_test_input_array( 'HTML5' ) );

return $html5_token_map;
}
Expand Down
Loading