Skip to content

Commit 8146100

Browse files
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
1 parent 31a6cd2 commit 8146100

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

tests/phpunit/includes/abstract-testcase.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -564,23 +564,25 @@ public function setExpectedIncorrectUsage( $doing_it_wrong ) {
564564
}
565565

566566
/**
567-
* PHPUnit 6+ compatibility shim.
567+
* Redundant PHPUnit 6+ compatibility shim. DO NOT USE!
568+
*
569+
* This method is only left in place for backward compatibility reasons.
570+
*
571+
* @deprecated 5.9.0 Use the PHPUnit native expectException*() methods directly.
568572
*
569573
* @param mixed $exception
570574
* @param string $message
571575
* @param int|string $code
572576
*/
573577
public function setExpectedException( $exception, $message = '', $code = null ) {
574-
if ( method_exists( 'PHPUnit_Framework_TestCase', 'setExpectedException' ) ) {
575-
parent::setExpectedException( $exception, $message, $code );
576-
} else {
577-
$this->expectException( $exception );
578-
if ( '' !== $message ) {
579-
$this->expectExceptionMessage( $message );
580-
}
581-
if ( null !== $code ) {
582-
$this->expectExceptionCode( $code );
583-
}
578+
$this->expectException( $exception );
579+
580+
if ( '' !== $message ) {
581+
$this->expectExceptionMessage( $message );
582+
}
583+
584+
if ( null !== $code ) {
585+
$this->expectExceptionCode( $code );
584586
}
585587
}
586588

0 commit comments

Comments
 (0)