Make WordPress Core

Changeset 52235


Ignore:
Timestamp:
11/23/2021 06:55:23 PM (3 years ago)
Author:
hellofromTonya
Message:

Build/Test Tools: Fix warnings from stdClass::__invoke() callback mocks in REST API tests.

When running core tests on PHPUnit 8.x and 9.x, four non-blocking warnings were displayed for the REST API tests:

There were 4 warnings:

1) Tests_REST_Request::test_route_level_validate_callback
createPartialMock called with method(s) __invoke that do not exist in stdClass. This will not be allowed in future versions of PHPUnit.

2) Tests_REST_Request::test_route_level_validate_callback_no_parameter_callbacks
createPartialMock called with method(s) __invoke that do not exist in stdClass. This will not be allowed in future versions of PHPUnit.

3) Tests_REST_Request::test_route_level_validate_callback_is_not_executed_if_parameter_validation_fails
createPartialMock called with method(s) __invoke that do not exist in stdClass. This will not be allowed in future versions of PHPUnit.

4) Tests_REST_Server::test_callbacks_are_not_executed_if_request_validation_fails
createPartialMock called with method(s) __invoke that do not exist in stdClass. This will not be allowed in future versions of PHPUnit.

These warnings are due to the PHP native stdClass not having a __invoke() method declared.

This commit adds a Mock_Invokable reusable class and replaces the stdClass with this new class.

Follow-up to [48945], [48947].

Props sourovroy, jrf.
Fixes #53844.

Location:
trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/phpcs.xml.dist

    r52179 r52235  
    250250                <element value="WP_Image_Editor_Mock"/>
    251251                <element value="WP_Filesystem_MockFS"/>
     252                <element value="Mock_Invokable"/>
    252253                <element value="MockPHPMailer"/>
    253254                <element value="MockAction"/>
  • trunk/tests/phpunit/tests/rest-api/rest-request.php

    r51657 r52235  
    1717
    1818        $this->request = new WP_REST_Request();
     19    }
     20
     21    /**
     22     * Called before setting up all tests.
     23     */
     24    public static function set_up_before_class() {
     25        parent::set_up_before_class();
     26
     27        // Require files that need to load once.
     28        require_once DIR_TESTROOT . '/includes/mock-invokable.php';
    1929    }
    2030
     
    10151025
    10161026        $error    = new WP_Error( 'error_code', __( 'Error Message' ), array( 'status' => 400 ) );
    1017         $callback = $this->createPartialMock( 'stdClass', array( '__invoke' ) );
     1027        $callback = $this->createPartialMock( 'Mock_Invokable', array( '__invoke' ) );
    10181028        $callback->expects( self::once() )->method( '__invoke' )->with( self::identicalTo( $request ) )->willReturn( $error );
    10191029        $request->set_attributes(
     
    10391049
    10401050        $error    = new WP_Error( 'error_code', __( 'Error Message' ), array( 'status' => 400 ) );
    1041         $callback = $this->createPartialMock( 'stdClass', array( '__invoke' ) );
     1051        $callback = $this->createPartialMock( 'Mock_Invokable', array( '__invoke' ) );
    10421052        $callback->expects( self::once() )->method( '__invoke' )->with( self::identicalTo( $request ) )->willReturn( $error );
    10431053        $request->set_attributes(
     
    10571067        $request->set_query_params( array( 'test' => 'value' ) );
    10581068
    1059         $callback = $this->createPartialMock( 'stdClass', array( '__invoke' ) );
     1069        $callback = $this->createPartialMock( 'Mock_Invokable', array( '__invoke' ) );
    10601070        $callback->expects( self::never() )->method( '__invoke' );
    10611071        $request->set_attributes(
  • trunk/tests/phpunit/tests/rest-api/rest-server.php

    r52080 r52235  
    3434
    3535        parent::tear_down();
     36    }
     37
     38    /**
     39     * Called before setting up all tests.
     40     */
     41    public static function set_up_before_class() {
     42        parent::set_up_before_class();
     43
     44        // Require files that need to load once.
     45        require_once DIR_TESTROOT . '/includes/mock-invokable.php';
    3646    }
    3747
     
    16311641     */
    16321642    public function test_callbacks_are_not_executed_if_request_validation_fails() {
    1633         $callback = $this->createPartialMock( 'stdClass', array( '__invoke' ) );
     1643        $callback = $this->createPartialMock( 'Mock_Invokable', array( '__invoke' ) );
    16341644        $callback->expects( self::never() )->method( '__invoke' );
    1635         $permission_callback = $this->createPartialMock( 'stdClass', array( '__invoke' ) );
     1645        $permission_callback = $this->createPartialMock( 'Mock_Invokable', array( '__invoke' ) );
    16361646        $permission_callback->expects( self::never() )->method( '__invoke' );
    16371647
Note: See TracChangeset for help on using the changeset viewer.