Skip to content

Commit c1f7f8a

Browse files
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
1 parent 0089ba1 commit c1f7f8a

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

tests/phpunit/tests/rest-api/rest-attachments-controller.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,12 +1102,12 @@ public function test_create_update_post_with_featured_media() {
11021102
$response = rest_get_server()->dispatch( $request );
11031103
$data = $response->get_data();
11041104

1105-
$this->assertEquals( 201, $response->get_status() );
1105+
$this->assertSame( 201, $response->get_status() );
11061106

11071107
$new_attachment = get_post( $data['id'] );
11081108

1109-
$this->assertEquals( $attachment_id, (int) get_post_thumbnail_id( $new_attachment->ID ) );
1110-
$this->assertEquals( $attachment_id, $data['featured_media'] );
1109+
$this->assertSame( $attachment_id, get_post_thumbnail_id( $new_attachment->ID ) );
1110+
$this->assertSame( $attachment_id, $data['featured_media'] );
11111111

11121112
$request = new WP_REST_Request( 'PUT', '/wp/v2/media/' . $new_attachment->ID );
11131113
$params = $this->set_post_data(
@@ -1117,10 +1117,10 @@ public function test_create_update_post_with_featured_media() {
11171117
);
11181118
$request->set_body_params( $params );
11191119
$response = rest_get_server()->dispatch( $request );
1120-
$this->assertEquals( 200, $response->get_status() );
1120+
$this->assertSame( 200, $response->get_status() );
11211121
$data = $response->get_data();
1122-
$this->assertEquals( 0, $data['featured_media'] );
1123-
$this->assertEquals( 0, (int) get_post_thumbnail_id( $new_attachment->ID ) );
1122+
$this->assertSame( 0, $data['featured_media'] );
1123+
$this->assertSame( 0, get_post_thumbnail_id( $new_attachment->ID ) );
11241124

11251125
$request = new WP_REST_Request( 'PUT', '/wp/v2/media/' . $new_attachment->ID );
11261126
$params = $this->set_post_data(
@@ -1130,10 +1130,10 @@ public function test_create_update_post_with_featured_media() {
11301130
);
11311131
$request->set_body_params( $params );
11321132
$response = rest_get_server()->dispatch( $request );
1133-
$this->assertEquals( 200, $response->get_status() );
1133+
$this->assertSame( 200, $response->get_status() );
11341134
$data = $response->get_data();
1135-
$this->assertEquals( $attachment_id, $data['featured_media'] );
1136-
$this->assertEquals( $attachment_id, (int) get_post_thumbnail_id( $new_attachment->ID ) );
1135+
$this->assertSame( $attachment_id, $data['featured_media'] );
1136+
$this->assertSame( $attachment_id, get_post_thumbnail_id( $new_attachment->ID ) );
11371137
}
11381138

11391139
public function test_update_item() {
@@ -2442,7 +2442,7 @@ public function test_edit_image() {
24422442

24432443
$this->assertStringEndsWith( '-edited.jpg', $item['media_details']['file'] );
24442444
$this->assertArrayHasKey( 'parent_image', $item['media_details'] );
2445-
$this->assertEquals( $attachment, $item['media_details']['parent_image']['attachment_id'] );
2445+
$this->assertSame( (string) $attachment, $item['media_details']['parent_image']['attachment_id'] );
24462446
$this->assertStringContainsString( 'canola', $item['media_details']['parent_image']['file'] );
24472447
}
24482448

@@ -2485,7 +2485,7 @@ public function test_batch_edit_image() {
24852485

24862486
$this->assertStringEndsWith( '-edited.jpg', $item['media_details']['file'] );
24872487
$this->assertArrayHasKey( 'parent_image', $item['media_details'] );
2488-
$this->assertEquals( $attachment, $item['media_details']['parent_image']['attachment_id'] );
2488+
$this->assertSame( (string) $attachment, $item['media_details']['parent_image']['attachment_id'] );
24892489
$this->assertStringContainsString( 'canola', $item['media_details']['parent_image']['file'] );
24902490
}
24912491

0 commit comments

Comments
 (0)