Skip to content

Commit

Permalink
Build/Test Tools: Simplify redundant PHPUnit shim for `setExpectedExc…
Browse files Browse the repository at this point in the history
…eption()`.

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
  • Loading branch information
SergeyBiryukov authored and SergeyBiryukov committed Aug 6, 2021
1 parent bb45292 commit 9de96a0
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions tests/phpunit/includes/abstract-testcase.php
Original file line number Diff line number Diff line change
Expand Up @@ -564,23 +564,25 @@ public function setExpectedIncorrectUsage( $doing_it_wrong ) {
}

/**
* 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 );
}
}

Expand Down

0 comments on commit 9de96a0

Please sign in to comment.