From 938bbb908918b607183fa1d9fa4de6db66871fd6 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Thu, 21 May 2026 16:26:47 +0200 Subject: [PATCH 1/4] Remove compatibility with versions of PHPUnit that are no longer used. --- tests/phpunit/includes/abstract-testcase.php | 29 ++---------- tests/phpunit/includes/bootstrap.php | 5 --- tests/phpunit/includes/functions.php | 12 +---- tests/phpunit/includes/phpunit6/compat.php | 47 -------------------- 4 files changed, 6 insertions(+), 87 deletions(-) delete mode 100644 tests/phpunit/includes/phpunit6/compat.php diff --git a/tests/phpunit/includes/abstract-testcase.php b/tests/phpunit/includes/abstract-testcase.php index b8e8598362ec5..980b6adb497b5 100644 --- a/tests/phpunit/includes/abstract-testcase.php +++ b/tests/phpunit/includes/abstract-testcase.php @@ -584,16 +584,10 @@ public function wp_die_handler( $message, $title, $args ) { * @since 3.7.0 */ public function expectDeprecated() { - if ( method_exists( $this, 'getAnnotations' ) ) { - // PHPUnit < 9.5.0. - $annotations = $this->getAnnotations(); - } else { - // PHPUnit >= 9.5.0. - $annotations = \PHPUnit\Util\Test::parseTestMethodAnnotations( - static::class, - $this->getName( false ) - ); - } + $annotations = \PHPUnit\Util\Test::parseTestMethodAnnotations( + static::class, + $this->getName( false ) + ); foreach ( array( 'class', 'method' ) as $depth ) { if ( ! empty( $annotations[ $depth ]['expectedDeprecated'] ) ) { @@ -1372,21 +1366,6 @@ public function go_to( $url ) { $GLOBALS['wp']->main( $parts['query'] ); } - /** - * Allows tests to be skipped on single or multisite installs by using @group annotations. - * - * This is a custom extension of the PHPUnit requirements handling. - * - * @since 3.5.0 - * @deprecated 5.9.0 This method has not been functional since PHPUnit 7.0. - */ - protected function checkRequirements() { - // For PHPUnit 5/6, as we're overloading a public PHPUnit native method in those versions. - if ( is_callable( 'PHPUnit\Framework\TestCase', 'checkRequirements' ) ) { - parent::checkRequirements(); - } - } - /** * Skips the current test if there is an open Trac ticket associated with it. * diff --git a/tests/phpunit/includes/bootstrap.php b/tests/phpunit/includes/bootstrap.php index e308dcb5a6e1c..4ac2b528e273e 100644 --- a/tests/phpunit/includes/bootstrap.php +++ b/tests/phpunit/includes/bootstrap.php @@ -308,11 +308,6 @@ function wp_tests_options( $value ) { // Delete any default posts & related data. _delete_all_posts(); -// Load class aliases for compatibility with PHPUnit 6+. -if ( version_compare( tests_get_phpunit_version(), '6.0', '>=' ) ) { - require __DIR__ . '/phpunit6/compat.php'; -} - require __DIR__ . '/phpunit-adapter-testcase.php'; require __DIR__ . '/abstract-testcase.php'; require __DIR__ . '/testcase.php'; diff --git a/tests/phpunit/includes/functions.php b/tests/phpunit/includes/functions.php index d6b6218278ae3..bda2a1a3a5163 100644 --- a/tests/phpunit/includes/functions.php +++ b/tests/phpunit/includes/functions.php @@ -4,18 +4,10 @@ /** * Retrieves PHPUnit runner version. * - * @return double The version number. + * @return string The version number. */ function tests_get_phpunit_version() { - if ( class_exists( 'PHPUnit\Runner\Version' ) ) { - $version = PHPUnit\Runner\Version::id(); - } elseif ( class_exists( 'PHPUnit_Runner_Version' ) ) { - $version = PHPUnit_Runner_Version::id(); - } else { - $version = 0; - } - - return $version; + return PHPUnit\Runner\Version::id(); } /** diff --git a/tests/phpunit/includes/phpunit6/compat.php b/tests/phpunit/includes/phpunit6/compat.php deleted file mode 100644 index b6c4a451033ed..0000000000000 --- a/tests/phpunit/includes/phpunit6/compat.php +++ /dev/null @@ -1,47 +0,0 @@ -=' ) ) { - - $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 ); - } - } - - class PHPUnit_Util_Test { - - // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid - public static function getTickets( $class_name, $method_name ) { - $annotations = PHPUnit\Util\Test::parseTestMethodAnnotations( $class_name, $method_name ); - - $tickets = array(); - - if ( isset( $annotations['class']['ticket'] ) ) { - $tickets = $annotations['class']['ticket']; - } - - if ( isset( $annotations['method']['ticket'] ) ) { - $tickets = array_merge( $tickets, $annotations['method']['ticket'] ); - } - - return array_unique( $tickets ); - } - } - -} From ffa4034ede21beaecfd3899770dbab1ff3cf5a0c Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Thu, 21 May 2026 16:27:02 +0200 Subject: [PATCH 2/4] Switch to the namespaced classes. --- tests/phpunit/includes/abstract-testcase.php | 2 +- tests/phpunit/includes/exceptions.php | 2 +- tests/phpunit/tests/admin/wpPrivacyRequestsTable.php | 2 +- tests/phpunit/tests/includes/helpers.php | 4 ++-- tests/phpunit/tests/widgets/wpWidgetMedia.php | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/phpunit/includes/abstract-testcase.php b/tests/phpunit/includes/abstract-testcase.php index 980b6adb497b5..4c5dad0de383f 100644 --- a/tests/phpunit/includes/abstract-testcase.php +++ b/tests/phpunit/includes/abstract-testcase.php @@ -1433,7 +1433,7 @@ public static function forceTicket( $ticket ) { */ public function prepareTemplate( Text_Template $template ) { $template->setVar( array( 'constants' => '' ) ); - $template->setVar( array( 'wp_constants' => PHPUnit_Util_GlobalState::getConstantsAsString() ) ); + $template->setVar( array( 'wp_constants' => PHPUnit\Util\GlobalState::getConstantsAsString() ) ); parent::prepareTemplate( $template ); } diff --git a/tests/phpunit/includes/exceptions.php b/tests/phpunit/includes/exceptions.php index 138c12e18cfc7..cbcc65fe089b2 100644 --- a/tests/phpunit/includes/exceptions.php +++ b/tests/phpunit/includes/exceptions.php @@ -1,6 +1,6 @@ assertSameSets( $expected, $actual ); - } catch ( PHPUnit_Framework_ExpectationFailedException $ex ) { + } catch ( PHPUnit\Framework\ExpectationFailedException $ex ) { return; } @@ -211,7 +211,7 @@ public function test_assertSameSetsWithIndex( $expected, $actual, $exception ) { if ( $exception ) { try { $this->assertSameSetsWithIndex( $expected, $actual ); - } catch ( PHPUnit_Framework_ExpectationFailedException $ex ) { + } catch ( PHPUnit\Framework\ExpectationFailedException $ex ) { return; } diff --git a/tests/phpunit/tests/widgets/wpWidgetMedia.php b/tests/phpunit/tests/widgets/wpWidgetMedia.php index 0334672c19384..61f89a20e9059 100644 --- a/tests/phpunit/tests/widgets/wpWidgetMedia.php +++ b/tests/phpunit/tests/widgets/wpWidgetMedia.php @@ -33,7 +33,7 @@ public function clean_up_global_scope() { * @param string $name Name for the widget displayed on the configuration page. * @param array $widget_options Optional. Widget options. * @param array $control_options Optional. Widget control options. - * @return PHPUnit_Framework_MockObject_MockObject|WP_Widget_Media Mocked instance. + * @return PHPUnit\Framework\MockObject\MockObject|WP_Widget_Media Mocked instance. */ private function get_mocked_class_instance( $id_base = 'mocked', $name = 'Mocked', $widget_options = array(), $control_options = array() ) { $original_class_name = 'WP_Widget_Media'; From 5bcefe9314f1de4d58fb0fbc7744e507bdf3bc65 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Thu, 21 May 2026 16:27:24 +0200 Subject: [PATCH 3/4] Update the PHPUnit version guard. --- tests/phpunit/includes/bootstrap.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/phpunit/includes/bootstrap.php b/tests/phpunit/includes/bootstrap.php index 4ac2b528e273e..538b80cba6f16 100644 --- a/tests/phpunit/includes/bootstrap.php +++ b/tests/phpunit/includes/bootstrap.php @@ -47,12 +47,12 @@ $phpunit_version = tests_get_phpunit_version(); -if ( version_compare( $phpunit_version, '5.7.21', '<' ) ) { +if ( version_compare( $phpunit_version, '9.0', '<' ) ) { printf( - "Error: Looks like you're using PHPUnit %s. WordPress requires at least PHPUnit 5.7.21." . PHP_EOL, + "Error: Looks like you're using PHPUnit %s. WordPress requires PHPUnit 9.x." . PHP_EOL, $phpunit_version ); - echo 'Please use the latest PHPUnit version supported for the PHP version you are running the tests on.' . PHP_EOL; + echo 'Please use the latest PHPUnit 9.x release supported for the PHP version you are running the tests on.' . PHP_EOL; exit( 1 ); } From 9197bd6112e1cdb2a2367a6aa21cb3abf0f56d5c Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Thu, 21 May 2026 17:06:02 +0100 Subject: [PATCH 4/4] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- tests/phpunit/includes/functions.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/phpunit/includes/functions.php b/tests/phpunit/includes/functions.php index bda2a1a3a5163..2cc941c8f65e8 100644 --- a/tests/phpunit/includes/functions.php +++ b/tests/phpunit/includes/functions.php @@ -7,6 +7,10 @@ * @return string The version number. */ function tests_get_phpunit_version() { + if ( ! class_exists( 'PHPUnit\\Runner\\Version' ) ) { + return '0'; + } + return PHPUnit\Runner\Version::id(); }