WordPress.org

Make WordPress Core

Opened 7 weeks ago

#53844 new defect (bug)

Fix four warnings in the test suite

Reported by: jrf Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Build/Test Tools Keywords: needs-patch
Focuses: rest-api Cc:

Description

Follow up after the projected changes for ticket #46149, which are expected to be committed soon.

When the WP Core tests are run on PHPUnit 8.x and 9.x, four - non-blocking - warnings will be displayed:

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 relate to the following code pattern which is used in all four of the referenced tests:

<?php
$callback = $this->createPartialMock( 'stdClass', array( '__invoke' ) );

The PHP native stdClass class does not have the __invoke() method declared.

As these warnings are currently non-blocking, they will not be addressed in ticket #46149. However, they should be addressed in the foreseeable future to prevent this becoming a blocker once PHPUnit 10 will be released.

Typically, this could be solved by declaring a dummy anonymous class with an __invoke() method, used only in the test suite, but anonymous classes is a PHP 7.0+ feature and can therefore not be used.

I suspect the best way to solve these warnings in a PHP cross-version compatible manner, will be to create a dummy class with an __invoke() method, as a test fixture and switching out the use of stdClass in these test methods in favour of using the dummy class.

Change History (0)

Note: See TracTickets for help on using tickets.