Make WordPress Core

Changeset 63880


Ignore:
Timestamp:
09/22/2026 11:04:55 PM (8 days ago)
Author:
lancewillett
Message:

Tests: Use strict assertions in additional test cases.

Replace loose equality and inequality assertions in selected core tests with strict comparisons where the fixtures and surrounding assertions establish the expected types.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/12583

Props soean, mukesh27, desrosj.
See #64895.

Location:
trunk/tests/phpunit/tests
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/customize/manager.php

    r63333 r63880  
    30423042                $url                     = 'http://badreferer.example.com/';
    30433043                $_SERVER['HTTP_REFERER'] = wp_slash( $url );
    3044                 $this->assertNotEquals( $url, $this->manager->get_return_url() );
     3044                $this->assertNotSame( $url, $this->manager->get_return_url() );
    30453045                $this->assertSame( $preview_url, $this->manager->get_return_url() );
    30463046
  • trunk/tests/phpunit/tests/customize/setting.php

    r63333 r63880  
    189189                        $this->assertSame( $overridden_value, call_user_func( $type_options['getter'], $name ), $message );
    190190                        $this->assertSame( $overridden_value, $setting->value(), $message );
    191                         $this->assertNotEquals( $initial_value, $setting->value(), $message );
     191                        $this->assertNotSame( $initial_value, $setting->value(), $message );
    192192
    193193                        // Non-multidimensional: Ensure that setting a post value *after* preview() is called results in the post value being seen (deferred preview).
    … …  
    196196                        $this->manager->set_post_value( $setting->id, $post_value );
    197197                        $this->assertSame( 1, did_action( "customize_post_value_set_{$setting->id}" ) );
    198                         $this->assertNotEquals( $overridden_value, $setting->value() );
     198                        $this->assertNotSame( $overridden_value, $setting->value() );
    199199                        $this->assertSame( $post_value, call_user_func( $type_options['getter'], $name ) );
    200200                        $this->assertSame( $post_value, $setting->value() );
  • trunk/tests/phpunit/tests/functions.php

    r63333 r63880  
    22682268        public function test_wp_get_default_extension_for_mime_type() {
    22692269                $this->assertSame( 'jpg', wp_get_default_extension_for_mime_type( 'image/jpeg' ), 'jpg not returned as default extension for "image/jpeg"' );
    2270                 $this->assertNotEquals( 'jpeg', wp_get_default_extension_for_mime_type( 'image/jpeg' ), 'jpeg should not be returned as default extension for "image/jpeg"' );
     2270                $this->assertNotSame( 'jpeg', wp_get_default_extension_for_mime_type( 'image/jpeg' ), 'jpeg should not be returned as default extension for "image/jpeg"' );
    22712271                $this->assertSame( 'png', wp_get_default_extension_for_mime_type( 'image/png' ), 'png not returned as default extension for "image/png"' );
    22722272                $this->assertFalse( wp_get_default_extension_for_mime_type( 'wibble/wobble' ), 'false not returned for unrecognized mime type' );
  • trunk/tests/phpunit/tests/icons/wpRestIconsController.php

    r63625 r63880  
    403403
    404404                $this->assertSame( 200, $response->get_status() );
    405                 $this->assertEquals( array( 'core/at-symbol' ), array_column( $data, 'name' ) );
     405                $this->assertSame( array( 'core/at-symbol' ), array_column( $data, 'name' ) );
    406406        }
    407407
  • trunk/tests/phpunit/tests/image/functions.php

    r60703 r63880  
    10151015
    10161016                // PDF preview didn't overwrite PDF.
    1017                 $this->assertNotEquals( $pdf_path, $preview_path );
     1017                $this->assertNotSame( $pdf_path, $preview_path );
    10181018                // PDF preview didn't overwrite JPG with same name.
    1019                 $this->assertNotEquals( $jpg1_path, $preview_path );
     1019                $this->assertNotSame( $jpg1_path, $preview_path );
    10201020                $this->assertSame( 'asdf', file_get_contents( $jpg1_path ) );
    10211021                // PDF preview didn't overwrite PDF preview with same name.
    1022                 $this->assertNotEquals( $jpg2_path, $preview_path );
     1022                $this->assertNotSame( $jpg2_path, $preview_path );
    10231023                $this->assertSame( 'fdsa', file_get_contents( $jpg2_path ) );
    10241024
  • trunk/tests/phpunit/tests/post.php

    r63616 r63880  
    274274                $post = get_post( $post_ids[ $key ] );
    275275                $this->assertSame( 'draft', $post->post_status );
    276                 $this->assertNotEquals( 'publish', $post->post_status );
     276                $this->assertNotSame( 'publish', $post->post_status );
    277277
    278278                $after_draft_counts = wp_count_posts();
    … …  
    295295                $post = get_post( $post_ids[ $key ] );
    296296                $this->assertSame( 'trash', $post->post_status );
    297                 $this->assertNotEquals( 'publish', $post->post_status );
     297                $this->assertNotSame( 'publish', $post->post_status );
    298298
    299299                $after_trash_counts = wp_count_posts();
  • trunk/tests/phpunit/tests/rest-api/rest-users-controller.php

    r63160 r63880  
    19961996
    19971997                $this->assertSame( 'editor', $new_data['roles'][0] );
    1998                 $this->assertNotEquals( 'administrator', $new_data['roles'][0] );
     1998                $this->assertNotSame( 'administrator', $new_data['roles'][0] );
    19991999
    20002000                $user = get_userdata( $user_id );
    … …  
    20912091                $new_data = $response->get_data();
    20922092                $this->assertSame( 'editor', $new_data['roles'][0] );
    2093                 $this->assertNotEquals( 'administrator', $new_data['roles'][0] );
     2093                $this->assertNotSame( 'administrator', $new_data['roles'][0] );
    20942094
    20952095                $user_id = self::factory()->user->create( array( 'role' => 'administrator' ) );
    … …  
    21052105                $new_data = $response->get_data();
    21062106                $this->assertSame( 'editor', $new_data['roles'][0] );
    2107                 $this->assertNotEquals( 'administrator', $new_data['roles'][0] );
     2107                $this->assertNotSame( 'administrator', $new_data['roles'][0] );
    21082108        }
    21092109
  • trunk/tests/phpunit/tests/rest-api/wpRestAbilitiesV1CategoriesController.php

    r62831 r63880  
    276276
    277277                $total_categories = count( wp_get_ability_categories() );
    278                 $this->assertEquals( $total_categories, (int) $headers['X-WP-Total'] );
     278                $this->assertSame( $total_categories, (int) $headers['X-WP-Total'] );
    279279                $this->assertEquals( ceil( $total_categories / 10 ), (int) $headers['X-WP-TotalPages'] );
    280280        }
  • trunk/tests/phpunit/tests/rest-api/wpRestAbilitiesV1ListController.php

    r62831 r63880  
    505505
    506506                $total_abilities = count( wp_get_abilities() ) - 1; // Exclude the one that doesn't show in REST.
    507                 $this->assertEquals( $total_abilities, (int) $headers['X-WP-Total'] );
     507                $this->assertSame( $total_abilities, (int) $headers['X-WP-Total'] );
    508508                $this->assertEquals( ceil( $total_abilities / 10 ), (int) $headers['X-WP-TotalPages'] );
    509509        }
  • trunk/tests/phpunit/tests/script-modules/wpScriptModules.php

    r63628 r63880  
    25862586                $script_modules = get_echo( array( wp_script_modules(), 'print_enqueued_script_modules' ) );
    25872587
    2588                 $this->assertEquals(
     2588                $this->assertSame(
    25892589                        array(
    25902590                                'static1'  => '/static1.js',
  • trunk/tests/phpunit/tests/template.php

    r63628 r63880  
    753753                $processed_output = ob_get_clean(); // Obtain the output via the wrapper output buffer.
    754754                $this->assertIsString( $processed_output );
    755                 $this->assertNotEquals( $original_output, $processed_output );
     755                $this->assertNotSame( $original_output, $processed_output );
    756756
    757757                $this->assertStringContainsString( '<!DOCTYPE html>', $processed_output, 'Expected processed output to contain string.' );
  • trunk/tests/phpunit/tests/term/wpInsertTerm.php

    r63616 r63880  
    845845                $this->assertIsInt( $t1 );
    846846                $this->assertIsInt( $t2 );
    847                 $this->assertNotEquals( $t1, $t2 );
     847                $this->assertNotSame( $t1, $t2 );
    848848
    849849                $term_2 = get_term( $t2, 'wptests_tax' );
  • trunk/tests/phpunit/tests/theme/themeDir.php

    r58264 r63880  
    314314
    315315                foreach ( $GLOBALS['wp_theme_directories'] as $dir ) {
    316                         $this->assertNotEquals( '/', substr( $dir, -1 ) );
     316                        $this->assertNotSame( '/', substr( $dir, -1 ) );
    317317                }
    318318
Note: See TracChangeset for help on using the changeset viewer.