From 90b6ae994322514aa049afd1cec654416be5043a Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sun, 26 Sep 2021 03:27:10 +0000 Subject: [PATCH] Tests: Update the `Services_JSON` test for PHPUnit 9.5.10/8.5.21+. Since PHPUnit 9.5.10 and 8.5.21, PHP deprecations are no longer converted to exceptions by default (`convertDeprecationsToExceptions="true"` can be configured to enable this). Reference: [https://github.com/sebastianbergmann/phpunit/commit/fac02620f6b38ae54d47fe840e0095e68226a56c Do not convert PHP deprecations to exceptions by default]; [https://github.com/sebastianbergmann/phpunit/blob/9.5.10/ChangeLog-9.5.md#9510---2021-09-25 PHPUnit 9.5.10 changelog]. With this change, the test for the `Services_JSON` compat class started failing: {{{ There was 1 failure: 1) Tests_Compat_jsonEncodeDecode::test_json_encode_decode Failed asserting that exception of type "PHPUnit\Framework\Error\Deprecated" is thrown. }}} This converts the native PHPUnit `::expectDeprecation()` method call in the test to a set of individual WP-specific `::setExpectedDeprecated()` method calls in order to not depend on PHPUnit behavior that is no longer the default. Additionally, this commit includes support for catching deprecation notices from `_deprecated_file()` function calls to the `WP_UnitTestCase_Base::expectDeprecated()` method. Follow-up to [46205], [46625], [48996], [51563], [51852], [51871]. Props jrf, netweb, SergeyBiryukov. See #54183, #54029, #53363. git-svn-id: https://develop.svn.wordpress.org/trunk@51872 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/includes/abstract-testcase.php | 2 ++ tests/phpunit/tests/compat/jsonEncodeDecode.php | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/includes/abstract-testcase.php b/tests/phpunit/includes/abstract-testcase.php index 49dfc0fef7..3cfe3991ea 100644 --- a/tests/phpunit/includes/abstract-testcase.php +++ b/tests/phpunit/includes/abstract-testcase.php @@ -503,10 +503,12 @@ abstract class WP_UnitTestCase_Base extends PHPUnit_Adapter_TestCase { } add_action( 'deprecated_function_run', array( $this, 'deprecated_function_run' ) ); add_action( 'deprecated_argument_run', array( $this, 'deprecated_function_run' ) ); + add_action( 'deprecated_file_included', array( $this, 'deprecated_function_run' ) ); add_action( 'deprecated_hook_run', array( $this, 'deprecated_function_run' ) ); add_action( 'doing_it_wrong_run', array( $this, 'doing_it_wrong_run' ) ); add_action( 'deprecated_function_trigger_error', '__return_false' ); add_action( 'deprecated_argument_trigger_error', '__return_false' ); + add_action( 'deprecated_file_trigger_error', '__return_false' ); add_action( 'deprecated_hook_trigger_error', '__return_false' ); add_action( 'doing_it_wrong_trigger_error', '__return_false' ); } diff --git a/tests/phpunit/tests/compat/jsonEncodeDecode.php b/tests/phpunit/tests/compat/jsonEncodeDecode.php index 475af85b9f..be51c6022b 100644 --- a/tests/phpunit/tests/compat/jsonEncodeDecode.php +++ b/tests/phpunit/tests/compat/jsonEncodeDecode.php @@ -8,7 +8,15 @@ class Tests_Compat_jsonEncodeDecode extends WP_UnitTestCase { public function test_json_encode_decode() { - $this->expectDeprecation(); + $this->setExpectedDeprecated( 'class-json.php' ); + $this->setExpectedDeprecated( 'Services_JSON::__construct' ); + $this->setExpectedDeprecated( 'Services_JSON::encodeUnsafe' ); + $this->setExpectedDeprecated( 'Services_JSON::_encode' ); + $this->setExpectedDeprecated( 'Services_JSON::reduce_string' ); + $this->setExpectedDeprecated( 'Services_JSON::decode' ); + $this->setExpectedDeprecated( 'Services_JSON::isError' ); + $this->setExpectedDeprecated( 'Services_JSON::strlen8' ); + $this->setExpectedDeprecated( 'Services_JSON::substr8' ); require_once ABSPATH . WPINC . '/class-json.php'; $json = new Services_JSON();