From e8ea993ce7a4f26d0a7796a8f87a750744f34762 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sat, 7 Aug 2021 11:00:52 +0000 Subject: [PATCH] Build/Test Tools: Handle removal of `TestCase::getAnnotations()`. The PHPUnit native `TestCase::getAnnotations()` method is used to check for WP flavored deprecation notices, however, this method was not covered by the backward compatibility promise for PHPUnit (and was annotated as excluded). The method has been removed as part of an internal refactor in commit [https://github.com/sebastianbergmann/phpunit/commit/68582043e149039cfa3596b42ed35753dcf54fb2 sebastianbergmann/phpunit@6858204], which is included in PHPUnit 9.5.0. For now, a workaround is put in place, but it is recommended that the WP `expectDeprecated()` method should be reevaluated in a future iteration. Follow-up to [51559-51571]. Props jrf. See #46149. git-svn-id: https://develop.svn.wordpress.org/trunk@51572 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/includes/abstract-testcase.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/includes/abstract-testcase.php b/tests/phpunit/includes/abstract-testcase.php index d5dccc9d16..a169754c69 100644 --- a/tests/phpunit/includes/abstract-testcase.php +++ b/tests/phpunit/includes/abstract-testcase.php @@ -472,7 +472,17 @@ abstract class WP_UnitTestCase_Base extends PHPUnit_Adapter_TestCase { * Sets up the expectations for testing a deprecated call. */ public function expectDeprecated() { - $annotations = $this->getAnnotations(); + 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 ) + ); + } + foreach ( array( 'class', 'method' ) as $depth ) { if ( ! empty( $annotations[ $depth ]['expectedDeprecated'] ) ) { $this->expected_deprecated = array_merge( $this->expected_deprecated, $annotations[ $depth ]['expectedDeprecated'] );