From cce0ff40ec12f8d5b44d4899bb1f699207d08327 Mon Sep 17 00:00:00 2001 From: thisismyurl <122108986+thisismyurl@users.noreply.github.com> Date: Mon, 20 Jul 2026 08:33:49 -0400 Subject: [PATCH] Build/Test Tools: Use strict assertions in REST schema sanitization tests Replace the remaining assertEquals() calls with assertSame() in the REST schema sanitization tests. These assertions exist to verify that rest_sanitize_value_from_schema() coerces a value to the type declared in the schema, so the type of the returned value is the whole point of the test. A loose assertion passes even when the sanitizer returns the uncoerced value, which hides exactly the class of bug these tests are meant to catch. The file already used assertSame() for the majority of its assertions, so this makes it consistent throughout. Props thisismyurl. See #64895. --- .../rest-api/rest-schema-sanitization.php | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/tests/phpunit/tests/rest-api/rest-schema-sanitization.php b/tests/phpunit/tests/rest-api/rest-schema-sanitization.php index 2cea494c064ea..c3aa8fa799eb5 100644 --- a/tests/phpunit/tests/rest-api/rest-schema-sanitization.php +++ b/tests/phpunit/tests/rest-api/rest-schema-sanitization.php @@ -111,8 +111,8 @@ public function test_type_array() { 'type' => 'number', ), ); - $this->assertEquals( array( 1 ), rest_sanitize_value_from_schema( array( 1 ), $schema ) ); - $this->assertEquals( array( 1 ), rest_sanitize_value_from_schema( array( '1' ), $schema ) ); + $this->assertSame( array( 1.0 ), rest_sanitize_value_from_schema( array( 1 ), $schema ) ); + $this->assertSame( array( 1.0 ), rest_sanitize_value_from_schema( array( '1' ), $schema ) ); } public function test_type_array_nested() { @@ -125,8 +125,8 @@ public function test_type_array_nested() { ), ), ); - $this->assertEquals( array( array( 1 ), array( 2 ) ), rest_sanitize_value_from_schema( array( array( 1 ), array( 2 ) ), $schema ) ); - $this->assertEquals( array( array( 1 ), array( 2 ) ), rest_sanitize_value_from_schema( array( array( '1' ), array( '2' ) ), $schema ) ); + $this->assertSame( array( array( 1.0 ), array( 2.0 ) ), rest_sanitize_value_from_schema( array( array( 1 ), array( 2 ) ), $schema ) ); + $this->assertSame( array( array( 1.0 ), array( 2.0 ) ), rest_sanitize_value_from_schema( array( array( '1' ), array( '2' ) ), $schema ) ); } public function test_type_array_as_csv() { @@ -136,9 +136,9 @@ public function test_type_array_as_csv() { 'type' => 'number', ), ); - $this->assertEquals( array( 1, 2 ), rest_sanitize_value_from_schema( '1,2', $schema ) ); - $this->assertEquals( array( 1, 2, 0 ), rest_sanitize_value_from_schema( '1,2,a', $schema ) ); - $this->assertEquals( array( 1, 2 ), rest_sanitize_value_from_schema( '1,2,', $schema ) ); + $this->assertSame( array( 1.0, 2.0 ), rest_sanitize_value_from_schema( '1,2', $schema ) ); + $this->assertSame( array( 1.0, 2.0, 0.0 ), rest_sanitize_value_from_schema( '1,2,a', $schema ) ); + $this->assertSame( array( 1.0, 2.0 ), rest_sanitize_value_from_schema( '1,2,', $schema ) ); } public function test_type_array_with_enum() { @@ -194,11 +194,11 @@ public function test_type_object() { ), ), ); - $this->assertEquals( array( 'a' => 1 ), rest_sanitize_value_from_schema( array( 'a' => 1 ), $schema ) ); - $this->assertEquals( array( 'a' => 1 ), rest_sanitize_value_from_schema( array( 'a' => '1' ), $schema ) ); - $this->assertEquals( + $this->assertSame( array( 'a' => 1.0 ), rest_sanitize_value_from_schema( array( 'a' => 1 ), $schema ) ); + $this->assertSame( array( 'a' => 1.0 ), rest_sanitize_value_from_schema( array( 'a' => '1' ), $schema ) ); + $this->assertSame( array( - 'a' => 1, + 'a' => 1.0, 'b' => 1, ), rest_sanitize_value_from_schema( @@ -221,10 +221,10 @@ public function test_type_object_strips_additional_properties() { ), 'additionalProperties' => false, ); - $this->assertEquals( array( 'a' => 1 ), rest_sanitize_value_from_schema( array( 'a' => 1 ), $schema ) ); - $this->assertEquals( array( 'a' => 1 ), rest_sanitize_value_from_schema( array( 'a' => '1' ), $schema ) ); - $this->assertEquals( - array( 'a' => 1 ), + $this->assertSame( array( 'a' => 1.0 ), rest_sanitize_value_from_schema( array( 'a' => 1 ), $schema ) ); + $this->assertSame( array( 'a' => 1.0 ), rest_sanitize_value_from_schema( array( 'a' => '1' ), $schema ) ); + $this->assertSame( + array( 'a' => 1.0 ), rest_sanitize_value_from_schema( array( 'a' => '1', @@ -345,11 +345,11 @@ public function test_type_object_nested() { ), ); - $this->assertEquals( + $this->assertSame( array( 'a' => array( - 'b' => 1, - 'c' => 3, + 'b' => 1.0, + 'c' => 3.0, ), ), rest_sanitize_value_from_schema( @@ -362,11 +362,11 @@ public function test_type_object_nested() { $schema ) ); - $this->assertEquals( + $this->assertSame( array( 'a' => array( - 'b' => 1, - 'c' => 3, + 'b' => 1.0, + 'c' => 3.0, 'd' => '1', ), 'b' => 1, @@ -395,7 +395,7 @@ public function test_type_object_stdclass() { ), ), ); - $this->assertEquals( array( 'a' => 1 ), rest_sanitize_value_from_schema( (object) array( 'a' => '1' ), $schema ) ); + $this->assertSame( array( 'a' => 1.0 ), rest_sanitize_value_from_schema( (object) array( 'a' => '1' ), $schema ) ); } /**