From cdd15a8f777859b57f2c64ae0ef61b5c9766d0fd Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sun, 20 Sep 2020 00:55:07 +0000 Subject: [PATCH] Tests: Fix the failures in REST API `format` keyword validation tests on PHP 8. The tests ensure that `rest_sanitize_value_from_schema()` and `rest_validate_value_from_schema()` throw an "undefined offset" notice when the required `type` schema keyword is not passed. In PHP 8, that notice is now a warning, so the tests need to be adjusted accordingly. Follow-up to [48300], [48993]. See #50913. git-svn-id: https://develop.svn.wordpress.org/trunk@49007 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/rest-api/rest-schema-sanitization.php | 7 ++++++- tests/phpunit/tests/rest-api/rest-schema-validation.php | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/tests/rest-api/rest-schema-sanitization.php b/tests/phpunit/tests/rest-api/rest-schema-sanitization.php index e91278bca5..dcefbd3034 100644 --- a/tests/phpunit/tests/rest-api/rest-schema-sanitization.php +++ b/tests/phpunit/tests/rest-api/rest-schema-sanitization.php @@ -360,7 +360,12 @@ class WP_Test_REST_Schema_Sanitization extends WP_UnitTestCase { * @ticket 50189 */ public function test_format_validation_is_applied_if_missing_type() { - $this->expectException( 'PHPUnit_Framework_Error_Notice' ); // For the undefined index. + if ( PHP_VERSION_ID >= 80000 ) { + $this->expectException( 'PHPUnit_Framework_Error_Warning' ); // For the undefined index. + } else { + $this->expectException( 'PHPUnit_Framework_Error_Notice' ); + } + $this->setExpectedIncorrectUsage( 'rest_sanitize_value_from_schema' ); $schema = array( 'format' => 'hex-color' ); diff --git a/tests/phpunit/tests/rest-api/rest-schema-validation.php b/tests/phpunit/tests/rest-api/rest-schema-validation.php index 4cb27010b8..a7cbc38e7d 100644 --- a/tests/phpunit/tests/rest-api/rest-schema-validation.php +++ b/tests/phpunit/tests/rest-api/rest-schema-validation.php @@ -156,7 +156,12 @@ class WP_Test_REST_Schema_Validation extends WP_UnitTestCase { * @ticket 50189 */ public function test_format_validation_is_applied_if_missing_type() { - $this->expectException( 'PHPUnit_Framework_Error_Notice' ); // For the undefined index. + if ( PHP_VERSION_ID >= 80000 ) { + $this->expectException( 'PHPUnit_Framework_Error_Warning' ); // For the undefined index. + } else { + $this->expectException( 'PHPUnit_Framework_Error_Notice' ); + } + $this->setExpectedIncorrectUsage( 'rest_validate_value_from_schema' ); $schema = array( 'format' => 'email' );