diff --git a/tests/phpunit/includes/abstract-testcase.php b/tests/phpunit/includes/abstract-testcase.php index b8e8598362ec5..4c5dad0de383f 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. * @@ -1454,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/bootstrap.php b/tests/phpunit/includes/bootstrap.php index e308dcb5a6e1c..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 ); } @@ -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/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 @@ =' ) ) { - - $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 ); - } - } - -} diff --git a/tests/phpunit/tests/admin/wpPrivacyRequestsTable.php b/tests/phpunit/tests/admin/wpPrivacyRequestsTable.php index 66e3e02501cfb..3618f42497e18 100644 --- a/tests/phpunit/tests/admin/wpPrivacyRequestsTable.php +++ b/tests/phpunit/tests/admin/wpPrivacyRequestsTable.php @@ -34,7 +34,7 @@ public function tear_down() { * * @since 5.1.0 * - * @return PHPUnit_Framework_MockObject_MockObject|WP_Privacy_Requests_Table Mocked class instance. + * @return PHPUnit\Framework\MockObject\MockObject|WP_Privacy_Requests_Table Mocked class instance. */ public function get_mocked_class_instance() { $args = array( diff --git a/tests/phpunit/tests/includes/helpers.php b/tests/phpunit/tests/includes/helpers.php index 5b9b83f463f94..3914357955929 100644 --- a/tests/phpunit/tests/includes/helpers.php +++ b/tests/phpunit/tests/includes/helpers.php @@ -55,7 +55,7 @@ public function test_assertSameSets( $expected, $actual, $exception ) { if ( $exception ) { try { $this->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';