Skip to content

Commit e8ea993

Browse files
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 [sebastianbergmann/phpunit@6858204 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
1 parent 60dcae9 commit e8ea993

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

tests/phpunit/includes/abstract-testcase.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,17 @@ public function wp_die_handler( $message ) {
472472
* Sets up the expectations for testing a deprecated call.
473473
*/
474474
public function expectDeprecated() {
475-
$annotations = $this->getAnnotations();
475+
if ( method_exists( $this, 'getAnnotations' ) ) {
476+
// PHPUnit < 9.5.0.
477+
$annotations = $this->getAnnotations();
478+
} else {
479+
// PHPUnit >= 9.5.0.
480+
$annotations = \PHPUnit\Util\Test::parseTestMethodAnnotations(
481+
static::class,
482+
$this->getName( false )
483+
);
484+
}
485+
476486
foreach ( array( 'class', 'method' ) as $depth ) {
477487
if ( ! empty( $annotations[ $depth ]['expectedDeprecated'] ) ) {
478488
$this->expected_deprecated = array_merge( $this->expected_deprecated, $annotations[ $depth ]['expectedDeprecated'] );

0 commit comments

Comments
 (0)