diff options
author | Sergey Biryukov <sergeybiryukov@git.wordpress.org> | 2025-03-22 16:06:25 +0000 |
---|---|---|
committer | Sergey Biryukov <sergeybiryukov@git.wordpress.org> | 2025-03-22 16:06:25 +0000 |
commit | c1f7f8a36c8f69708899b055a3d3618fbee08012 (patch) | |
tree | eb4d208ca6535a9e7fc7c550d5b1a4af32bb49ae /tests | |
parent | 0089ba1c2c44a0d5cd3de36602c1610aec493a43 (diff) | |
download | wordpress-c1f7f8a36c8f69708899b055a3d3618fbee08012.tar.gz wordpress-c1f7f8a36c8f69708899b055a3d3618fbee08012.zip |
Tests: Use `assertSame()` in REST API attachments controller 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 [48291], [50124], [57603].
See #62278.
git-svn-id: https://develop.svn.wordpress.org/trunk@60068 602fd350-edb4-49c9-b593-d223f7449a82
Diffstat (limited to 'tests')
-rw-r--r-- | tests/phpunit/tests/rest-api/rest-attachments-controller.php | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/tests/phpunit/tests/rest-api/rest-attachments-controller.php b/tests/phpunit/tests/rest-api/rest-attachments-controller.php index cdd3159d50..5794bf944d 100644 --- a/tests/phpunit/tests/rest-api/rest-attachments-controller.php +++ b/tests/phpunit/tests/rest-api/rest-attachments-controller.php @@ -1102,12 +1102,12 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control $response = rest_get_server()->dispatch( $request ); $data = $response->get_data(); - $this->assertEquals( 201, $response->get_status() ); + $this->assertSame( 201, $response->get_status() ); $new_attachment = get_post( $data['id'] ); - $this->assertEquals( $attachment_id, (int) get_post_thumbnail_id( $new_attachment->ID ) ); - $this->assertEquals( $attachment_id, $data['featured_media'] ); + $this->assertSame( $attachment_id, get_post_thumbnail_id( $new_attachment->ID ) ); + $this->assertSame( $attachment_id, $data['featured_media'] ); $request = new WP_REST_Request( 'PUT', '/wp/v2/media/' . $new_attachment->ID ); $params = $this->set_post_data( @@ -1117,10 +1117,10 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control ); $request->set_body_params( $params ); $response = rest_get_server()->dispatch( $request ); - $this->assertEquals( 200, $response->get_status() ); + $this->assertSame( 200, $response->get_status() ); $data = $response->get_data(); - $this->assertEquals( 0, $data['featured_media'] ); - $this->assertEquals( 0, (int) get_post_thumbnail_id( $new_attachment->ID ) ); + $this->assertSame( 0, $data['featured_media'] ); + $this->assertSame( 0, get_post_thumbnail_id( $new_attachment->ID ) ); $request = new WP_REST_Request( 'PUT', '/wp/v2/media/' . $new_attachment->ID ); $params = $this->set_post_data( @@ -1130,10 +1130,10 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control ); $request->set_body_params( $params ); $response = rest_get_server()->dispatch( $request ); - $this->assertEquals( 200, $response->get_status() ); + $this->assertSame( 200, $response->get_status() ); $data = $response->get_data(); - $this->assertEquals( $attachment_id, $data['featured_media'] ); - $this->assertEquals( $attachment_id, (int) get_post_thumbnail_id( $new_attachment->ID ) ); + $this->assertSame( $attachment_id, $data['featured_media'] ); + $this->assertSame( $attachment_id, get_post_thumbnail_id( $new_attachment->ID ) ); } public function test_update_item() { @@ -2442,7 +2442,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control $this->assertStringEndsWith( '-edited.jpg', $item['media_details']['file'] ); $this->assertArrayHasKey( 'parent_image', $item['media_details'] ); - $this->assertEquals( $attachment, $item['media_details']['parent_image']['attachment_id'] ); + $this->assertSame( (string) $attachment, $item['media_details']['parent_image']['attachment_id'] ); $this->assertStringContainsString( 'canola', $item['media_details']['parent_image']['file'] ); } @@ -2485,7 +2485,7 @@ class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control $this->assertStringEndsWith( '-edited.jpg', $item['media_details']['file'] ); $this->assertArrayHasKey( 'parent_image', $item['media_details'] ); - $this->assertEquals( $attachment, $item['media_details']['parent_image']['attachment_id'] ); + $this->assertSame( (string) $attachment, $item['media_details']['parent_image']['attachment_id'] ); $this->assertStringContainsString( 'canola', $item['media_details']['parent_image']['file'] ); } |