Skip to content

Commit ed2f2ec

Browse files
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 [59630]. See #62278. git-svn-id: https://develop.svn.wordpress.org/trunk@59985 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 59f3fef commit ed2f2ec

File tree

4 files changed

+24
-24
lines changed

4 files changed

+24
-24
lines changed

tests/phpunit/tests/rest-api/rest-global-styles-revisions-controller.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -958,22 +958,22 @@ public function test_get_global_styles_revisions_pagination() {
958958
$request->set_param( 'offset', 1 );
959959
$request->set_param( 'per_page', 1 );
960960
$response = rest_get_server()->dispatch( $request );
961-
$this->assertEquals( 200, $response->get_status() );
961+
$this->assertSame( 200, $response->get_status() );
962962
$data = $response->get_data();
963963
$this->assertCount( 1, $data );
964-
$this->assertEquals( 3, $response->get_headers()['X-WP-Total'] );
965-
$this->assertEquals( 3, $response->get_headers()['X-WP-TotalPages'] );
964+
$this->assertSame( 3, $response->get_headers()['X-WP-Total'] );
965+
$this->assertSame( 3, $response->get_headers()['X-WP-TotalPages'] );
966966

967967
// Test paged.
968968
$request = new WP_REST_Request( 'GET', '/wp/v2/global-styles/' . self::$global_styles_id . '/revisions' );
969969
$request->set_param( 'page', 2 );
970970
$request->set_param( 'per_page', 2 );
971971
$response = rest_get_server()->dispatch( $request );
972-
$this->assertEquals( 200, $response->get_status() );
972+
$this->assertSame( 200, $response->get_status() );
973973
$data = $response->get_data();
974974
$this->assertCount( 1, $data );
975-
$this->assertEquals( 3, $response->get_headers()['X-WP-Total'] );
976-
$this->assertEquals( 2, $response->get_headers()['X-WP-TotalPages'] );
975+
$this->assertSame( 3, $response->get_headers()['X-WP-Total'] );
976+
$this->assertSame( 2, $response->get_headers()['X-WP-TotalPages'] );
977977

978978
// Test out of bounds.
979979
$request = new WP_REST_Request( 'GET', '/wp/v2/global-styles/' . self::$global_styles_id . '/revisions' );

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5944,22 +5944,22 @@ public function test_get_posts_with_pagination() {
59445944
$request->set_param( 'offset', 1 );
59455945
$request->set_param( 'per_page', 1 );
59465946
$response = rest_get_server()->dispatch( $request );
5947-
$this->assertEquals( 200, $response->get_status() );
5947+
$this->assertSame( 200, $response->get_status() );
59485948
$data = $response->get_data();
59495949
$this->assertCount( 1, $data );
5950-
$this->assertEquals( 30, $response->get_headers()['X-WP-Total'] );
5951-
$this->assertEquals( 30, $response->get_headers()['X-WP-TotalPages'] );
5950+
$this->assertSame( 30, $response->get_headers()['X-WP-Total'] );
5951+
$this->assertSame( 30, $response->get_headers()['X-WP-TotalPages'] );
59525952

59535953
// Test paged.
59545954
$request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
59555955
$request->set_param( 'page', 2 );
59565956
$request->set_param( 'per_page', 2 );
59575957
$response = rest_get_server()->dispatch( $request );
5958-
$this->assertEquals( 200, $response->get_status() );
5958+
$this->assertSame( 200, $response->get_status() );
59595959
$data = $response->get_data();
59605960
$this->assertCount( 2, $data );
5961-
$this->assertEquals( 30, $response->get_headers()['X-WP-Total'] );
5962-
$this->assertEquals( 15, $response->get_headers()['X-WP-TotalPages'] );
5961+
$this->assertSame( 30, $response->get_headers()['X-WP-Total'] );
5962+
$this->assertSame( 15, $response->get_headers()['X-WP-TotalPages'] );
59635963

59645964
// Test out of bounds.
59655965
$request = new WP_REST_Request( 'GET', '/wp/v2/posts' );

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,22 +1057,22 @@ public function test_get_revisions_pagination() {
10571057
$request->set_param( 'offset', 1 );
10581058
$request->set_param( 'per_page', 1 );
10591059
$response = rest_get_server()->dispatch( $request );
1060-
$this->assertEquals( 200, $response->get_status() );
1060+
$this->assertSame( 200, $response->get_status() );
10611061
$data = $response->get_data();
10621062
$this->assertCount( 1, $data );
1063-
$this->assertEquals( $this->total_revisions, $response->get_headers()['X-WP-Total'] );
1064-
$this->assertEquals( $this->total_revisions, $response->get_headers()['X-WP-TotalPages'] );
1063+
$this->assertSame( $this->total_revisions, $response->get_headers()['X-WP-Total'] );
1064+
$this->assertSame( $this->total_revisions, $response->get_headers()['X-WP-TotalPages'] );
10651065

10661066
// Test paged.
10671067
$request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . self::$post_id . '/revisions' );
10681068
$request->set_param( 'page', 2 );
10691069
$request->set_param( 'per_page', 2 );
10701070
$response = rest_get_server()->dispatch( $request );
1071-
$this->assertEquals( 200, $response->get_status() );
1071+
$this->assertSame( 200, $response->get_status() );
10721072
$data = $response->get_data();
10731073
$this->assertCount( 1, $data );
1074-
$this->assertEquals( $this->total_revisions, $response->get_headers()['X-WP-Total'] );
1075-
$this->assertEquals( (int) ceil( $this->total_revisions / 2 ), $response->get_headers()['X-WP-TotalPages'] );
1074+
$this->assertSame( $this->total_revisions, $response->get_headers()['X-WP-Total'] );
1075+
$this->assertSame( (int) ceil( $this->total_revisions / 2 ), $response->get_headers()['X-WP-TotalPages'] );
10761076

10771077
// Test out of bounds.
10781078
$request = new WP_REST_Request( 'GET', '/wp/v2/posts/' . self::$post_id . '/revisions' );

tests/phpunit/tests/rest-api/wpRestTemplateRevisionsController.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,22 +1196,22 @@ public function test_get_template_revisions_pagination() {
11961196
$request->set_param( 'offset', 1 );
11971197
$request->set_param( 'per_page', 1 );
11981198
$response = rest_get_server()->dispatch( $request );
1199-
$this->assertEquals( 200, $response->get_status() );
1199+
$this->assertSame( 200, $response->get_status() );
12001200
$data = $response->get_data();
12011201
$this->assertCount( 1, $data );
1202-
$this->assertEquals( 4, $response->get_headers()['X-WP-Total'] );
1203-
$this->assertEquals( 4, $response->get_headers()['X-WP-TotalPages'] );
1202+
$this->assertSame( 4, $response->get_headers()['X-WP-Total'] );
1203+
$this->assertSame( 4, $response->get_headers()['X-WP-TotalPages'] );
12041204

12051205
// Test paged.
12061206
$request = new WP_REST_Request( 'GET', '/wp/v2/templates/' . self::TEST_THEME . '/' . self::TEMPLATE_NAME . '/revisions' );
12071207
$request->set_param( 'page', 2 );
12081208
$request->set_param( 'per_page', 2 );
12091209
$response = rest_get_server()->dispatch( $request );
1210-
$this->assertEquals( 200, $response->get_status() );
1210+
$this->assertSame( 200, $response->get_status() );
12111211
$data = $response->get_data();
12121212
$this->assertCount( 2, $data );
1213-
$this->assertEquals( 4, $response->get_headers()['X-WP-Total'] );
1214-
$this->assertEquals( 2, $response->get_headers()['X-WP-TotalPages'] );
1213+
$this->assertSame( 4, $response->get_headers()['X-WP-Total'] );
1214+
$this->assertSame( 2, $response->get_headers()['X-WP-TotalPages'] );
12151215

12161216
// Test out of bounds.
12171217
$request = new WP_REST_Request( 'GET', '/wp/v2/templates/' . self::TEST_THEME . '/' . self::TEMPLATE_NAME . '/revisions' );

0 commit comments

Comments
 (0)