From 4f4ecd4b29048fbffcbfc1e1b3af94c3fb314504 Mon Sep 17 00:00:00 2001 From: shail-mehta Date: Sat, 31 Oct 2026 05:45:43 +0000 Subject: [PATCH 1/2] Tests: Cover rest_are_values_equal(). Add unit tests for JSON Schema value equality across scalars, int/float coercion, and arrays. See #65819. --- .../tests/rest-api/restAreValuesEqual.php | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 tests/phpunit/tests/rest-api/restAreValuesEqual.php diff --git a/tests/phpunit/tests/rest-api/restAreValuesEqual.php b/tests/phpunit/tests/rest-api/restAreValuesEqual.php new file mode 100644 index 0000000000000..d35c3ff27b49a --- /dev/null +++ b/tests/phpunit/tests/rest-api/restAreValuesEqual.php @@ -0,0 +1,92 @@ +assertTrue( rest_are_values_equal( $value1, $value2 ) ); + } + + /** + * Data provider. + * + * @return array[] + */ + public static function data_equal_values() { + return array( + 'same strings' => array( 'hello', 'hello' ), + 'same integers' => array( 7, 7 ), + 'integer and float' => array( 1, 1.0 ), + 'float and integer' => array( 1.0, 1 ), + 'same booleans' => array( true, true ), + 'both null' => array( null, null ), + 'same lists' => array( array( 1, 2 ), array( 1, 2 ) ), + 'same objects different key order' => array( + array( + 'a' => 1, + 'b' => 2, + ), + array( + 'b' => 2, + 'a' => 1, + ), + ), + 'nested arrays' => array( + array( + 'items' => array( 1, array( 'x' => 2 ) ), + ), + array( + 'items' => array( 1, array( 'x' => 2 ) ), + ), + ), + ); + } + + /** + * @ticket 65819 + * + * @dataProvider data_unequal_values + * + * @param mixed $value1 First value. + * @param mixed $value2 Second value. + */ + public function test_returns_false_for_unequal_values( $value1, $value2 ) { + $this->assertFalse( rest_are_values_equal( $value1, $value2 ) ); + } + + /** + * Data provider. + * + * @return array[] + */ + public static function data_unequal_values() { + return array( + 'different strings' => array( 'hello', 'world' ), + 'string and integer' => array( '1', 1 ), + 'different list order' => array( array( 1, 2 ), array( 2, 1 ) ), + 'different counts' => array( array( 1 ), array( 1, 2 ) ), + 'missing object key' => array( + array( 'a' => 1 ), + array( 'b' => 1 ), + ), + 'nested mismatch' => array( + array( 'items' => array( 1, 2 ) ), + array( 'items' => array( 1, 3 ) ), + ), + ); + } +} From 9f9fc2fed4b896288d838f46f20d03e5686dbfc6 Mon Sep 17 00:00:00 2001 From: shail-mehta Date: Sat, 31 Oct 2026 05:57:32 +0000 Subject: [PATCH 2/2] Tests: Strengthen rest_are_values_equal() coverage. Add null object properties, nested int/float coercion with reordered keys, and unequal mixed-number cases. Align data provider arrows for PHPCS. See #65819. --- .../tests/rest-api/restAreValuesEqual.php | 54 +++++++++++++------ 1 file changed, 39 insertions(+), 15 deletions(-) diff --git a/tests/phpunit/tests/rest-api/restAreValuesEqual.php b/tests/phpunit/tests/rest-api/restAreValuesEqual.php index d35c3ff27b49a..360620dae203b 100644 --- a/tests/phpunit/tests/rest-api/restAreValuesEqual.php +++ b/tests/phpunit/tests/rest-api/restAreValuesEqual.php @@ -28,13 +28,23 @@ public function test_returns_true_for_equal_values( $value1, $value2 ) { */ public static function data_equal_values() { return array( - 'same strings' => array( 'hello', 'hello' ), - 'same integers' => array( 7, 7 ), - 'integer and float' => array( 1, 1.0 ), - 'float and integer' => array( 1.0, 1 ), - 'same booleans' => array( true, true ), - 'both null' => array( null, null ), - 'same lists' => array( array( 1, 2 ), array( 1, 2 ) ), + 'same strings' => array( 'hello', 'hello' ), + 'same integers' => array( 7, 7 ), + 'integer and float' => array( 1, 1.0 ), + 'float and integer' => array( 1.0, 1 ), + 'same booleans' => array( true, true ), + 'both null' => array( null, null ), + 'same lists' => array( array( 1, 2 ), array( 1, 2 ) ), + 'objects with null property' => array( + array( + 'a' => null, + 'b' => 1, + ), + array( + 'a' => null, + 'b' => 1, + ), + ), 'same objects different key order' => array( array( 'a' => 1, @@ -45,12 +55,24 @@ public static function data_equal_values() { 'a' => 1, ), ), - 'nested arrays' => array( + 'nested coercion and key order' => array( array( - 'items' => array( 1, array( 'x' => 2 ) ), + 'items' => array( + 1, + array( + 'x' => 2, + 'y' => 3.0, + ), + ), ), array( - 'items' => array( 1, array( 'x' => 2 ) ), + 'items' => array( + 1.0, + array( + 'y' => 3, + 'x' => 2.0, + ), + ), ), ), ); @@ -75,15 +97,17 @@ public function test_returns_false_for_unequal_values( $value1, $value2 ) { */ public static function data_unequal_values() { return array( - 'different strings' => array( 'hello', 'world' ), - 'string and integer' => array( '1', 1 ), + 'different strings' => array( 'hello', 'world' ), + 'string and integer' => array( '1', 1 ), + 'integer and float' => array( 1, 2.0 ), + 'float and integer' => array( 2.0, 1 ), 'different list order' => array( array( 1, 2 ), array( 2, 1 ) ), - 'different counts' => array( array( 1 ), array( 1, 2 ) ), - 'missing object key' => array( + 'different counts' => array( array( 1 ), array( 1, 2 ) ), + 'missing object key' => array( array( 'a' => 1 ), array( 'b' => 1 ), ), - 'nested mismatch' => array( + 'nested mismatch' => array( array( 'items' => array( 1, 2 ) ), array( 'items' => array( 1, 3 ) ), ),