Skip to content

Remove redundant PHPUnit compat#11925

Draft
johnbillion wants to merge 5 commits into
WordPress:trunkfrom
johnbillion:remove-phpunit-compat
Draft

Remove redundant PHPUnit compat#11925
johnbillion wants to merge 5 commits into
WordPress:trunkfrom
johnbillion:remove-phpunit-compat

Conversation

@johnbillion
Copy link
Copy Markdown
Member

@johnbillion johnbillion commented May 21, 2026

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.

@github-actions
Copy link
Copy Markdown

Test using WordPress Playground

The 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

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@johnbillion johnbillion marked this pull request as ready for review May 21, 2026 16:01
@johnbillion johnbillion requested a review from Copilot May 21, 2026 16:01
@github-actions
Copy link
Copy Markdown

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props johnbillion.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread tests/phpunit/includes/functions.php
Comment thread tests/phpunit/includes/bootstrap.php
johnbillion and others added 2 commits May 21, 2026 17:06
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Member

@desrosj desrosj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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".

Comment on lines -5 to -25
$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 );
}
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@johnbillion johnbillion marked this pull request as draft May 22, 2026 08:44
@johnbillion johnbillion moved this from In review to In progress in WordPress Project Build Tooling May 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In progress

Development

Successfully merging this pull request may close these issues.

3 participants