Skip to content

Commit 5e1eb2c

Browse files
committed
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: #12583 Props soean, mukesh27, desrosj. See #64895. git-svn-id: https://develop.svn.wordpress.org/trunk@63880 602fd350-edb4-49c9-b593-d223f7449a82
1 parent f3d7e9a commit 5e1eb2c

13 files changed

Lines changed: 19 additions & 19 deletions

‎tests/phpunit/tests/customize/manager.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3041,7 +3041,7 @@ public function test_return_url() {
30413041

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

30473047
$this->manager->set_return_url( admin_url( 'edit.php?trashed=1' ) );

‎tests/phpunit/tests/customize/setting.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,14 +188,14 @@ public function test_preview_standard_types_non_multidimensional() {
188188
$message = 'Initial value should be overridden because initial preview() was no-op due to setting having existing value and/or post value was absent.';
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).
194194
$post_value = "post_value_for_{$setting->id}_set_after_preview_called";
195195
$this->assertSame( 0, did_action( "customize_post_value_set_{$setting->id}" ) );
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() );
201201

‎tests/phpunit/tests/functions.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2267,7 +2267,7 @@ public function data_wp_is_json_media_type() {
22672267
*/
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' );
22732273
$this->assertFalse( wp_get_default_extension_for_mime_type( '' ), 'false not returned when empty string as mime type supplied' );

‎tests/phpunit/tests/icons/wpRestIconsController.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ public function test_get_items_search_includes_label() {
402402
$data = $response->get_data();
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

408408
/**

‎tests/phpunit/tests/image/functions.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,12 +1014,12 @@ public function test_pdf_preview_doesnt_overwrite_existing_jpeg() {
10141014
$preview_path = $temp_dir . $metadata['sizes']['full']['file'];
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

10251025
// Cleanup.

‎tests/phpunit/tests/post.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ public function test_wp_count_posts_insert_invalidation() {
273273

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();
279279
$this->assertSame( '1', $after_draft_counts->draft );
@@ -294,7 +294,7 @@ public function test_wp_count_posts_trash_invalidation() {
294294

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();
300300
$this->assertSame( '1', $after_trash_counts->trash );

‎tests/phpunit/tests/rest-api/rest-users-controller.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1995,7 +1995,7 @@ public function test_update_user_role() {
19951995
$new_data = $response->get_data();
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 );
20012001
$this->assertArrayHasKey( 'editor', $user->caps );
@@ -2090,7 +2090,7 @@ public function test_update_user_role_privilege_deescalation_multisite() {
20902090

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' ) );
20962096

@@ -2104,7 +2104,7 @@ public function test_update_user_role_privilege_deescalation_multisite() {
21042104

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

21102110

‎tests/phpunit/tests/rest-api/wpRestAbilitiesV1CategoriesController.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ public function test_pagination_headers(): void {
275275
$this->assertArrayHasKey( 'X-WP-TotalPages', $headers );
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
}
281281

‎tests/phpunit/tests/rest-api/wpRestAbilitiesV1ListController.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ public function test_pagination_headers(): void {
504504
$this->assertArrayHasKey( 'X-WP-TotalPages', $headers );
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
}
510510

‎tests/phpunit/tests/script-modules/wpScriptModules.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2585,7 +2585,7 @@ public function test_static_import_dependency_with_dynamic_imports_depending_on_
25852585
$preload_links = get_echo( array( wp_script_modules(), 'print_script_module_preloads' ) );
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',
25912591
'dynamic1' => '/dynamic1.js',

0 commit comments

Comments
 (0)