From 81461004d72e706b967d35003f064d992cb5f684 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Fri, 6 Aug 2021 21:17:20 +0000 Subject: [PATCH] Build/Test Tools: Simplify redundant PHPUnit shim for `setExpectedException()`. PHPUnit 6 deprecated the `setExpectedException()` method in favor of the `expectException()`, `expectExceptionMessage()`, and `expectExceptionCode()` methods. `WP_UnitTestCase_Base::setExpectedException()` backfilled the old method. As the PHPUnit Polyfills have a polyfill for the ''new'' method, this backfill can now be simplified. This backfill ''should'' be removed in a future iteration, but is, for now, left in place so as not to break backward compatibility for plugin/theme test suites which extend the WP native test suite for their integration tests. Follow-up to [48996], [48997], [51559-51561]. Props jrf. See #46149. git-svn-id: https://develop.svn.wordpress.org/trunk@51562 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/includes/abstract-testcase.php | 24 +++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/tests/phpunit/includes/abstract-testcase.php b/tests/phpunit/includes/abstract-testcase.php index 933859571b..59ea4635fd 100644 --- a/tests/phpunit/includes/abstract-testcase.php +++ b/tests/phpunit/includes/abstract-testcase.php @@ -564,23 +564,25 @@ abstract class WP_UnitTestCase_Base extends PHPUnit_Adapter_TestCase { } /** - * PHPUnit 6+ compatibility shim. + * Redundant PHPUnit 6+ compatibility shim. DO NOT USE! + * + * This method is only left in place for backward compatibility reasons. + * + * @deprecated 5.9.0 Use the PHPUnit native expectException*() methods directly. * * @param mixed $exception * @param string $message * @param int|string $code */ public function setExpectedException( $exception, $message = '', $code = null ) { - if ( method_exists( 'PHPUnit_Framework_TestCase', 'setExpectedException' ) ) { - parent::setExpectedException( $exception, $message, $code ); - } else { - $this->expectException( $exception ); - if ( '' !== $message ) { - $this->expectExceptionMessage( $message ); - } - if ( null !== $code ) { - $this->expectExceptionCode( $code ); - } + $this->expectException( $exception ); + + if ( '' !== $message ) { + $this->expectExceptionMessage( $message ); + } + + if ( null !== $code ) { + $this->expectExceptionCode( $code ); } }