-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #200 from Yoast/feature/3.x/new-expectuserdeprecat…
…ion-polyfill-trait PHPUnit 11 | ExpectUserDeprecationtrait: polyfill the TestCase::expectUserDeprecation*() methods
- Loading branch information
Showing
13 changed files
with
199 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
namespace Yoast\PHPUnitPolyfills\Polyfills; | ||
|
||
use PHPUnit\Framework\Error\Deprecated; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* Polyfill the TestCase::expectUserDeprecationMessage() and the TestCase::expectUserDeprecationMessageMatches() methods. | ||
* | ||
* Introduced in PHPUnit 11.0.0. | ||
* | ||
* Note: PHPUnit 10 is not and will not be supported for these polyfills. | ||
* | ||
* @link https://github.com/sebastianbergmann/phpunit/pull/5605 | ||
*/ | ||
trait ExpectUserDeprecation { | ||
|
||
/** | ||
* Set expectation for the message when receiving a user defined deprecation notice. | ||
* | ||
* @param string $expectedUserDeprecationMessage The message to expect. | ||
* | ||
* @return void | ||
*/ | ||
final protected function expectUserDeprecationMessage( string $expectedUserDeprecationMessage ) { | ||
if ( \method_exists( TestCase::class, 'expectDeprecationMessage' ) ) { | ||
// PHPUnit 8.4.0 - 9.x. | ||
$this->expectDeprecation(); | ||
$this->expectDeprecationMessage( $expectedUserDeprecationMessage ); | ||
return; | ||
} | ||
|
||
// PHPUnit < 8.4.0. | ||
$this->expectException( Deprecated::class ); | ||
$this->expectExceptionMessage( $expectedUserDeprecationMessage ); | ||
} | ||
|
||
/** | ||
* Set expectation for the message when receiving a user defined deprecation notice (regex based). | ||
* | ||
* @param string $expectedUserDeprecationMessageRegularExpression A regular expression which must match the message. | ||
* | ||
* @return void | ||
*/ | ||
final protected function expectUserDeprecationMessageMatches( string $expectedUserDeprecationMessageRegularExpression ) { | ||
if ( \method_exists( TestCase::class, 'expectDeprecationMessageMatches' ) ) { | ||
// PHPUnit 8.4.0 - 9.x. | ||
$this->expectDeprecation(); | ||
$this->expectDeprecationMessageMatches( $expectedUserDeprecationMessageRegularExpression ); | ||
return; | ||
} | ||
|
||
// PHPUnit < 8.4.0. | ||
$this->expectException( Deprecated::class ); | ||
$this->expectExceptionMessageRegExp( $expectedUserDeprecationMessageRegularExpression ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace Yoast\PHPUnitPolyfills\Polyfills; | ||
|
||
/** | ||
* Empty trait for use with PHPUnit >= 11.0.0 in which this polyfill is not needed. | ||
*/ | ||
trait ExpectUserDeprecation {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.