From b9ca649f3b7749a7dd40fdf1b31962b3c83b3b86 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sat, 6 Jan 2024 12:59:49 +0000 Subject: [PATCH] Tests: Use `assertSame()` in some newly introduced tests. This ensures that not only the return values match the expected results, but also that their type is the same. Going forward, stricter type checking by using `assertSame()` should generally be preferred to `assertEquals()` where appropriate, to make the tests more reliable. Follow-up to [55859], [56380], [56802], [57115], [57129], [57185]. See #59655. git-svn-id: https://develop.svn.wordpress.org/trunk@57244 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/ajax/wpAjaxImageEditor.php | 2 +- tests/phpunit/tests/ajax/wpAjaxInlineSave.php | 8 ++++---- tests/phpunit/tests/dependencies/scripts.php | 2 +- .../tests/html-api/wpHtmlProcessorSemanticRules.php | 6 +++--- tests/phpunit/tests/theme.php | 8 ++++---- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/phpunit/tests/ajax/wpAjaxImageEditor.php b/tests/phpunit/tests/ajax/wpAjaxImageEditor.php index ac761c3520..89745d6458 100644 --- a/tests/phpunit/tests/ajax/wpAjaxImageEditor.php +++ b/tests/phpunit/tests/ajax/wpAjaxImageEditor.php @@ -52,7 +52,7 @@ class Tests_Ajax_wpAjaxImageEditor extends WP_Ajax_UnitTestCase { $ret = wp_save_image( $id ); $this->assertObjectHasProperty( 'error', $ret ); - $this->assertEquals( 'Images cannot be scaled to a size larger than the original.', $ret->error ); + $this->assertSame( 'Images cannot be scaled to a size larger than the original.', $ret->error ); } /** diff --git a/tests/phpunit/tests/ajax/wpAjaxInlineSave.php b/tests/phpunit/tests/ajax/wpAjaxInlineSave.php index 2edd630de8..afb73e6dcf 100644 --- a/tests/phpunit/tests/ajax/wpAjaxInlineSave.php +++ b/tests/phpunit/tests/ajax/wpAjaxInlineSave.php @@ -110,7 +110,7 @@ class Tests_Ajax_wpAjaxInlineSave extends WP_Ajax_UnitTestCase { $this->assertSame( 'draft', $post->post_status ); - $this->assertEquals( '0000-00-00 00:00:00', $post->post_date_gmt ); + $this->assertSame( '0000-00-00 00:00:00', $post->post_date_gmt ); // Set up a request. $_POST['_inline_edit'] = wp_create_nonce( 'inlineeditnonce' ); @@ -142,7 +142,7 @@ class Tests_Ajax_wpAjaxInlineSave extends WP_Ajax_UnitTestCase { $post_date = sprintf( '%04d-%02d-%02d %02d:%02d:%02d', $_POST['aa'], $_POST['mm'], $_POST['jj'], $_POST['hh'], $_POST['mn'], $_POST['ss'] ); - $this->assertEquals( '0000-00-00 00:00:00', $post->post_date_gmt ); + $this->assertSame( '0000-00-00 00:00:00', $post->post_date_gmt ); } /** @@ -167,7 +167,7 @@ class Tests_Ajax_wpAjaxInlineSave extends WP_Ajax_UnitTestCase { $this->assertSame( 'draft', $post->post_status ); - $this->assertEquals( '0000-00-00 00:00:00', $post->post_date_gmt ); + $this->assertSame( '0000-00-00 00:00:00', $post->post_date_gmt ); // Set up a request. $_POST['_inline_edit'] = wp_create_nonce( 'inlineeditnonce' ); @@ -197,6 +197,6 @@ class Tests_Ajax_wpAjaxInlineSave extends WP_Ajax_UnitTestCase { $post = get_post( $post->ID ); - $this->assertEquals( '2020-09-11 19:20:11', $post->post_date_gmt ); + $this->assertSame( '2020-09-11 19:20:11', $post->post_date_gmt ); } } diff --git a/tests/phpunit/tests/dependencies/scripts.php b/tests/phpunit/tests/dependencies/scripts.php index 9021397e3b..2280771880 100644 --- a/tests/phpunit/tests/dependencies/scripts.php +++ b/tests/phpunit/tests/dependencies/scripts.php @@ -3366,7 +3366,7 @@ HTML wp_default_packages_vendor( $wp_scripts ); - $this->assertEquals( $package_json[ $script ], $wp_scripts->query( $script, 'registered' )->ver ); + $this->assertSame( $package_json[ $script ], $wp_scripts->query( $script, 'registered' )->ver ); } public function data_wp_default_packages_vendor() { diff --git a/tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRules.php b/tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRules.php index 7bd243d8dc..bd3996d51d 100644 --- a/tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRules.php +++ b/tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRules.php @@ -35,7 +35,7 @@ class Tests_HtmlApi_WpHtmlProcessorSemanticRules extends WP_UnitTestCase { continue; } - $this->assertEquals( + $this->assertSame( $tag_name, $processor->get_tag(), "Expected to find {$tag_name} but found {$processor->get_tag()} instead." @@ -125,7 +125,7 @@ class Tests_HtmlApi_WpHtmlProcessorSemanticRules extends WP_UnitTestCase { $p = WP_HTML_Processor::create_fragment( '
Test
' ); $p->step(); - $this->assertEquals( 'DIV', $p->get_tag(), 'Did not stop at initial DIV tag.' ); + $this->assertSame( 'DIV', $p->get_tag(), 'Did not stop at initial DIV tag.' ); $this->assertFalse( $p->is_tag_closer(), 'Did not find that initial DIV tag is an opener.' ); /* @@ -133,7 +133,7 @@ class Tests_HtmlApi_WpHtmlProcessorSemanticRules extends WP_UnitTestCase { * It should be ignored as there's no BUTTON to close. */ $this->assertTrue( $p->step(), 'Found no further tags when it should have found the closing DIV' ); - $this->assertEquals( 'DIV', $p->get_tag(), "Did not skip unexpected BUTTON; stopped at {$p->get_tag()}." ); + $this->assertSame( 'DIV', $p->get_tag(), "Did not skip unexpected BUTTON; stopped at {$p->get_tag()}." ); $this->assertTrue( $p->is_tag_closer(), 'Did not find that the terminal DIV tag is a closer.' ); } diff --git a/tests/phpunit/tests/theme.php b/tests/phpunit/tests/theme.php index cf5ea9ad6c..a70bf9e7ff 100644 --- a/tests/phpunit/tests/theme.php +++ b/tests/phpunit/tests/theme.php @@ -1259,8 +1259,8 @@ class Tests_Theme extends WP_UnitTestCase { // Cleanup. switch_theme( $old_theme->get_stylesheet() ); - $this->assertEquals( $old_root . '/test', $path1, 'The original stylesheet path is not correct' ); - $this->assertEquals( $new_root . '/test', $path2, 'The new stylesheet path is not correct' ); + $this->assertSame( $old_root . '/test', $path1, 'The original stylesheet path is not correct' ); + $this->assertSame( $new_root . '/test', $path2, 'The new stylesheet path is not correct' ); } /** @@ -1302,7 +1302,7 @@ class Tests_Theme extends WP_UnitTestCase { // Cleanup. switch_theme( $old_theme->get_stylesheet() ); - $this->assertEquals( $old_root . '/test-parent', $path1, 'The original template path is not correct' ); - $this->assertEquals( $new_root . '/test-parent', $path2, 'The new template path is not correct' ); + $this->assertSame( $old_root . '/test-parent', $path1, 'The original template path is not correct' ); + $this->assertSame( $new_root . '/test-parent', $path2, 'The new template path is not correct' ); } }