From b05838f5707d5469c8a0ada4bee09f886784a7e6 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 19 Feb 2024 15:05:46 +0000 Subject: [PATCH] Tests: Use `assertSame()` in `WP_REST_Navigation_Fallback_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 [56052]. See #59655. git-svn-id: https://develop.svn.wordpress.org/trunk@57656 602fd350-edb4-49c9-b593-d223f7449a82 --- .../rest-navigation-fallback-controller.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/phpunit/tests/rest-api/rest-navigation-fallback-controller.php b/tests/phpunit/tests/rest-api/rest-navigation-fallback-controller.php index efcbe9eb8d..b8d7c25c32 100644 --- a/tests/phpunit/tests/rest-api/rest-navigation-fallback-controller.php +++ b/tests/phpunit/tests/rest-api/rest-navigation-fallback-controller.php @@ -61,11 +61,11 @@ class WP_REST_Navigation_Fallback_Controller_Test extends WP_Test_REST_Controlle $response = rest_get_server()->dispatch( $request ); $data = $response->get_data(); - $this->assertEquals( 403, $response->get_status(), 'Response should indicate user does not have permission.' ); + $this->assertSame( 403, $response->get_status(), 'Response should indicate user does not have permission.' ); - $this->assertEquals( 'rest_cannot_create', $data['code'], 'Response should indicate user cannot create.' ); + $this->assertSame( 'rest_cannot_create', $data['code'], 'Response should indicate user cannot create.' ); - $this->assertEquals( 'Sorry, you are not allowed to create Navigation Menus as this user.', $data['message'], 'Response should indicate failed request status.' ); + $this->assertSame( 'Sorry, you are not allowed to create Navigation Menus as this user.', $data['message'], 'Response should indicate failed request status.' ); } /** @@ -80,13 +80,13 @@ class WP_REST_Navigation_Fallback_Controller_Test extends WP_Test_REST_Controlle $response = rest_get_server()->dispatch( $request ); $data = $response->get_data(); - $this->assertEquals( 200, $response->get_status(), 'Status should indicate successful request.' ); + $this->assertSame( 200, $response->get_status(), 'Status should indicate successful request.' ); $this->assertIsArray( $data, 'Response should be of correct type.' ); $this->assertArrayHasKey( 'id', $data, 'Response should contain expected fields.' ); - $this->assertEquals( 'wp_navigation', get_post_type( $data['id'] ), '"id" field should represent a post of type "wp_navigation"' ); + $this->assertSame( 'wp_navigation', get_post_type( $data['id'] ), '"id" field should represent a post of type "wp_navigation"' ); // Check that only a single Navigation fallback was created. $navs_in_db = $this->get_navigations_in_database(); @@ -105,16 +105,16 @@ class WP_REST_Navigation_Fallback_Controller_Test extends WP_Test_REST_Controlle $response = rest_get_server()->dispatch( $request ); $data = $response->get_data(); - $this->assertEquals( 200, $response->get_status(), 'Status should indicate successful request.' ); + $this->assertSame( 200, $response->get_status(), 'Status should indicate successful request.' ); $this->assertArrayHasKey( 'schema', $data, '"schema" key should exist in response.' ); $schema = $data['schema']; - $this->assertEquals( 'object', $schema['type'], 'The schema type should match the expected type.' ); + $this->assertSame( 'object', $schema['type'], 'The schema type should match the expected type.' ); $this->assertArrayHasKey( 'id', $schema['properties'], 'Schema should have an "id" property.' ); - $this->assertEquals( 'integer', $schema['properties']['id']['type'], 'Schema "id" property should be an integer.' ); + $this->assertSame( 'integer', $schema['properties']['id']['type'], 'Schema "id" property should be an integer.' ); $this->assertTrue( $schema['properties']['id']['readonly'], 'Schema "id" property should be readonly.' ); }