[wp-trac] [WordPress Trac] #53844: Fix four warnings in the test suite
WordPress Trac
noreply at wordpress.org
Fri Jul 30 22:38:29 UTC 2021
#53844: Fix four warnings in the test suite
------------------------------+-----------------------------
Reporter: jrf | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Build/Test Tools | Version:
Severity: normal | Keywords: needs-patch
Focuses: rest-api |
------------------------------+-----------------------------
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
<?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.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/53844>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list