From 3a196ba35419939bd2d66d6411200c58f9bd5303 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Wed, 21 Feb 2024 17:33:54 +0000 Subject: [PATCH] Tests: Use `assertSame()` in `wp_insert_post()` 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 [34085], [35183], [48937], [53782], [53785], [53883], [54402]. Props costdev. See #59655. git-svn-id: https://develop.svn.wordpress.org/trunk@57680 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/post/wpInsertPost.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/phpunit/tests/post/wpInsertPost.php b/tests/phpunit/tests/post/wpInsertPost.php index 1b0838cf06..701a48bdea 100644 --- a/tests/phpunit/tests/post/wpInsertPost.php +++ b/tests/phpunit/tests/post/wpInsertPost.php @@ -128,7 +128,7 @@ class Tests_Post_wpInsertPost extends WP_UnitTestCase { $this->assertSame( $data['post_content'], $post->post_content ); $this->assertSame( $data['post_title'], $post->post_title ); $this->assertSame( $data['post_status'], $post->post_status ); - $this->assertEquals( $data['post_author'], $post->post_author ); + $this->assertSame( (string) $data['post_author'], $post->post_author ); // Test cache state. $post_cache = wp_cache_get( $post_id, 'posts' ); @@ -675,7 +675,7 @@ class Tests_Post_wpInsertPost extends WP_UnitTestCase { $this->assertGreaterThan( 0, $post_id ); $post = get_post( $post_id ); - $this->assertEquals( self::$user_ids['editor'], $post->post_author ); + $this->assertSame( (string) self::$user_ids['editor'], $post->post_author ); $this->assertSame( $title, $post->post_title ); } @@ -787,7 +787,7 @@ class Tests_Post_wpInsertPost extends WP_UnitTestCase { public function test_wp_insert_post_author_zero() { $post_id = self::factory()->post->create( array( 'post_author' => 0 ) ); - $this->assertEquals( 0, get_post( $post_id )->post_author ); + $this->assertSame( '0', get_post( $post_id )->post_author ); } /** @@ -798,7 +798,7 @@ class Tests_Post_wpInsertPost extends WP_UnitTestCase { $post_id = self::factory()->post->create( array( 'post_author' => null ) ); - $this->assertEquals( self::$user_ids['editor'], get_post( $post_id )->post_author ); + $this->assertSame( (string) self::$user_ids['editor'], get_post( $post_id )->post_author ); } /** @@ -916,7 +916,7 @@ class Tests_Post_wpInsertPost extends WP_UnitTestCase { // Validate that the post has had the default category assigned again. $this->assertCount( 1, $assigned_terms ); - $this->assertEquals( get_option( 'default_category' ), $assigned_terms[0]->term_id ); + $this->assertSame( (int) get_option( 'default_category' ), $assigned_terms[0]->term_id ); } /**