Remove redundant PHPUnit compat#11925
Conversation
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
There was a problem hiding this comment.
Pull request overview
This PR removes legacy PHPUnit compatibility shims in the WordPress PHPUnit test suite, aligning the test bootstrap and related helpers with PHPUnit 9 as the only supported runner version.
Changes:
- Removes PHPUnit 6 compatibility aliases/shims and updates remaining legacy class references to PHPUnit 9 namespaces.
- Updates the test bootstrap to require PHPUnit 9.x and removes the conditional loading of the old compat layer.
- Simplifies/modernizes test internals (annotation parsing, global-state template handling) assuming PHPUnit 9 APIs.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/phpunit/tests/widgets/wpWidgetMedia.php | Updates mock-object return type docblock to PHPUnit 9 namespace. |
| tests/phpunit/tests/includes/helpers.php | Updates caught exception type to PHPUnit 9 ExpectationFailedException. |
| tests/phpunit/tests/admin/wpPrivacyRequestsTable.php | Updates mock-object return type docblock to PHPUnit 9 namespace. |
| tests/phpunit/includes/phpunit6/compat.php | Removes PHPUnit 6 compatibility aliasing/shims. |
| tests/phpunit/includes/functions.php | Simplifies PHPUnit version detection to use PHPUnit\\Runner\\Version. |
| tests/phpunit/includes/exceptions.php | Updates base exception type to PHPUnit 9 namespace. |
| tests/phpunit/includes/bootstrap.php | Raises minimum PHPUnit requirement to 9.x and removes loading of PHPUnit 6 compat. |
| tests/phpunit/includes/abstract-testcase.php | Removes older annotation/requirements compat paths and updates GlobalState reference. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
desrosj
left a comment
There was a problem hiding this comment.
I agree with the majority of changes here, but I do have a few concerns about how the others would affect the broader ecosystem.
| */ | ||
| public function expectDeprecated() { | ||
| if ( method_exists( $this, 'getAnnotations' ) ) { | ||
| // PHPUnit < 9.5.0. |
There was a problem hiding this comment.
I'm less concerned about this change than the removal of the aliases. However, I am wondering if this is worth leaving because someone could be using PHPUnit 9.4, 9.3, etc. Removing this would not be in the spirit of "PHPUnit 9 as the only version currently in use".
| $aliases = array( | ||
| 'PHPUnit\Framework\TestCase' => 'PHPUnit_Framework_TestCase', | ||
| 'PHPUnit\Framework\Exception' => 'PHPUnit_Framework_Exception', | ||
| 'PHPUnit\Framework\ExpectationFailedException' => 'PHPUnit_Framework_ExpectationFailedException', | ||
| 'PHPUnit\Framework\Error\Deprecated' => 'PHPUnit_Framework_Error_Deprecated', | ||
| 'PHPUnit\Framework\Error\Notice' => 'PHPUnit_Framework_Error_Notice', | ||
| 'PHPUnit\Framework\Error\Warning' => 'PHPUnit_Framework_Error_Warning', | ||
| 'PHPUnit\Framework\Test' => 'PHPUnit_Framework_Test', | ||
| 'PHPUnit\Framework\Warning' => 'PHPUnit_Framework_Warning', | ||
| 'PHPUnit\Framework\AssertionFailedError' => 'PHPUnit_Framework_AssertionFailedError', | ||
| 'PHPUnit\Framework\TestSuite' => 'PHPUnit_Framework_TestSuite', | ||
| 'PHPUnit\Framework\TestListener' => 'PHPUnit_Framework_TestListener', | ||
| 'PHPUnit\Util\GlobalState' => 'PHPUnit_Util_GlobalState', | ||
| 'PHPUnit\Util\Getopt' => 'PHPUnit_Util_Getopt', | ||
| ); | ||
|
|
||
| foreach ( $aliases as $original => $alias ) { | ||
| if ( class_exists( $original ) ) { | ||
| class_alias( $original, $alias ); | ||
| } | ||
| } |
There was a problem hiding this comment.
I'm concerned about straight up removing these aliases without first performing some level of developer outreach first. The install-wp-tests.sh script created by the wp scaffold command in WP-CLI downloads the test suite and explicitly copies the includes directory into place.
I think the probability that plugin test suites are referencing these namespace-less class names is very high, especially since these aliases have just continued to work. This is likely true even for cases where a more recent version of PHPUnit is being used.
This removes some PHPUnit back-compat that's no longer needed.
This leaves PHPUnit 9 as the only version currently in use.
Trac ticket: https://core.trac.wordpress.org/ticket/64894
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Opus 4.7
Used for: Initial investigation and changes, with follow-ups and fixes by me.