From 0089ba1c2c44a0d5cd3de36602c1610aec493a43 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Fri, 21 Mar 2025 23:46:14 +0000 Subject: [PATCH] Tests: Use `assertSame()` in REST API schema sanitization 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 [39061], [48937]. See #62278. git-svn-id: https://develop.svn.wordpress.org/trunk@60067 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/rest-api/rest-schema-sanitization.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/phpunit/tests/rest-api/rest-schema-sanitization.php b/tests/phpunit/tests/rest-api/rest-schema-sanitization.php index 7cf88f243c..2cea494c06 100644 --- a/tests/phpunit/tests/rest-api/rest-schema-sanitization.php +++ b/tests/phpunit/tests/rest-api/rest-schema-sanitization.php @@ -13,11 +13,11 @@ class WP_Test_REST_Schema_Sanitization extends WP_UnitTestCase { $schema = array( 'type' => 'number', ); - $this->assertEquals( 1, rest_sanitize_value_from_schema( 1, $schema ) ); + $this->assertSame( 1.0, rest_sanitize_value_from_schema( 1, $schema ) ); $this->assertSame( 1.10, rest_sanitize_value_from_schema( '1.10', $schema ) ); - $this->assertEquals( 1, rest_sanitize_value_from_schema( '1abc', $schema ) ); - $this->assertEquals( 0, rest_sanitize_value_from_schema( 'abc', $schema ) ); - $this->assertEquals( 0, rest_sanitize_value_from_schema( array(), $schema ) ); + $this->assertSame( 1.0, rest_sanitize_value_from_schema( '1abc', $schema ) ); + $this->assertSame( 0.0, rest_sanitize_value_from_schema( 'abc', $schema ) ); + $this->assertSame( 0.0, rest_sanitize_value_from_schema( array(), $schema ) ); } public function test_type_integer() {