Make WordPress Core

Changeset 51872


Ignore:
Timestamp:
09/26/2021 03:27:10 AM (3 years ago)
Author:
SergeyBiryukov
Message:

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: Do not convert PHP deprecations to exceptions by default; 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.

Location:
trunk/tests/phpunit
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/includes/abstract-testcase.php

    r51831 r51872  
    504504        add_action( 'deprecated_function_run', array( $this, 'deprecated_function_run' ) );
    505505        add_action( 'deprecated_argument_run', array( $this, 'deprecated_function_run' ) );
     506        add_action( 'deprecated_file_included', array( $this, 'deprecated_function_run' ) );
    506507        add_action( 'deprecated_hook_run', array( $this, 'deprecated_function_run' ) );
    507508        add_action( 'doing_it_wrong_run', array( $this, 'doing_it_wrong_run' ) );
    508509        add_action( 'deprecated_function_trigger_error', '__return_false' );
    509510        add_action( 'deprecated_argument_trigger_error', '__return_false' );
     511        add_action( 'deprecated_file_trigger_error', '__return_false' );
    510512        add_action( 'deprecated_hook_trigger_error', '__return_false' );
    511513        add_action( 'doing_it_wrong_trigger_error', '__return_false' );
  • trunk/tests/phpunit/tests/compat/jsonEncodeDecode.php

    r51852 r51872  
    99
    1010    public function test_json_encode_decode() {
    11         $this->expectDeprecation();
     11        $this->setExpectedDeprecated( 'class-json.php' );
     12        $this->setExpectedDeprecated( 'Services_JSON::__construct' );
     13        $this->setExpectedDeprecated( 'Services_JSON::encodeUnsafe' );
     14        $this->setExpectedDeprecated( 'Services_JSON::_encode' );
     15        $this->setExpectedDeprecated( 'Services_JSON::reduce_string' );
     16        $this->setExpectedDeprecated( 'Services_JSON::decode' );
     17        $this->setExpectedDeprecated( 'Services_JSON::isError' );
     18        $this->setExpectedDeprecated( 'Services_JSON::strlen8' );
     19        $this->setExpectedDeprecated( 'Services_JSON::substr8' );
    1220
    1321        require_once ABSPATH . WPINC . '/class-json.php';
Note: See TracChangeset for help on using the changeset viewer.