From 6b9d6c0439d8319c6d76d21ff038009daa562a90 Mon Sep 17 00:00:00 2001 From: Thomas Calvet Date: Mon, 8 Jun 2020 18:05:40 +0200 Subject: [PATCH] [PhpUnitBridge] Fix ExpectDeprecationTrait::expectDeprecation() conflict --- .../Bridge/PhpUnit/ExpectDeprecationTrait.php | 23 ++++---- .../PhpUnit/Legacy/ExpectDeprecationTrait.php | 52 +++++++++++++++++++ .../ExpectDeprecationTraitBeforeV8_4.php | 32 ++++++++++++ 3 files changed, 93 insertions(+), 14 deletions(-) create mode 100644 src/Symfony/Bridge/PhpUnit/Legacy/ExpectDeprecationTrait.php create mode 100644 src/Symfony/Bridge/PhpUnit/Legacy/ExpectDeprecationTraitBeforeV8_4.php diff --git a/src/Symfony/Bridge/PhpUnit/ExpectDeprecationTrait.php b/src/Symfony/Bridge/PhpUnit/ExpectDeprecationTrait.php index 0db391d12abab..9e47aabeec4b1 100644 --- a/src/Symfony/Bridge/PhpUnit/ExpectDeprecationTrait.php +++ b/src/Symfony/Bridge/PhpUnit/ExpectDeprecationTrait.php @@ -11,21 +11,16 @@ namespace Symfony\Bridge\PhpUnit; -use Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerTrait; +use Symfony\Bridge\PhpUnit\Legacy\ExpectDeprecationTraitBeforeV8_4; -trait ExpectDeprecationTrait -{ - /** - * @param string $message - * - * @return void - */ - protected function expectDeprecation($message) +if (version_compare(\PHPUnit\Runner\Version::id(), '8.4.0', '<')) { + trait ExpectDeprecationTrait { - if (!SymfonyTestsListenerTrait::$previousErrorHandler) { - SymfonyTestsListenerTrait::$previousErrorHandler = set_error_handler([SymfonyTestsListenerTrait::class, 'handleError']); - } - - SymfonyTestsListenerTrait::$expectedDeprecations[] = $message; + use ExpectDeprecationTraitBeforeV8_4; + } +} else { + trait ExpectDeprecationTrait + { + use \Symfony\Bridge\PhpUnit\Legacy\ExpectDeprecationTrait; } } diff --git a/src/Symfony/Bridge/PhpUnit/Legacy/ExpectDeprecationTrait.php b/src/Symfony/Bridge/PhpUnit/Legacy/ExpectDeprecationTrait.php new file mode 100644 index 0000000000000..c37428087707d --- /dev/null +++ b/src/Symfony/Bridge/PhpUnit/Legacy/ExpectDeprecationTrait.php @@ -0,0 +1,52 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bridge\PhpUnit\Legacy; + +/** + * @internal use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait instead. + */ +trait ExpectDeprecationTrait +{ + /** + * @param string $message + */ + public function expectDeprecation(): void + { + if (1 > func_num_args() || !\is_string($message = func_get_arg(0))) { + throw new \InvalidArgumentException(sprintf('The "%s()" method requires the string $message argument.', __FUNCTION__)); + } + + \Closure::bind(function (string $message): void { + $this->expectDeprecation($message); + }, $o = new class() { + use ExpectDeprecationTraitBeforeV8_4 { + expectDeprecation as public; + } + })($message); + } + + /** + * @internal use expectDeprecation() instead. + */ + public function expectDeprecationMessage(string $message): void + { + throw new \BadMethodCallException(sprintf("The "%s()" method is not supported by Symfony's PHPUnit Bridge ExpectDeprecationTrait.", __FUNCTION__)); + } + + /** + * @internal use expectDeprecation() instead. + */ + public function expectDeprecationMessageMatches(string $regularExpression): void + { + throw new \BadMethodCallException(sprintf("The "%s()" method is not supported by Symfony's PHPUnit Bridge ExpectDeprecationTrait.", __FUNCTION__)); + } +} diff --git a/src/Symfony/Bridge/PhpUnit/Legacy/ExpectDeprecationTraitBeforeV8_4.php b/src/Symfony/Bridge/PhpUnit/Legacy/ExpectDeprecationTraitBeforeV8_4.php new file mode 100644 index 0000000000000..47c8226e6e556 --- /dev/null +++ b/src/Symfony/Bridge/PhpUnit/Legacy/ExpectDeprecationTraitBeforeV8_4.php @@ -0,0 +1,32 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bridge\PhpUnit\Legacy; + +/** + * @internal, use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait instead. + */ +trait ExpectDeprecationTraitBeforeV8_4 +{ + /** + * @param string $message + * + * @return void + */ + protected function expectDeprecation($message) + { + if (!SymfonyTestsListenerTrait::$previousErrorHandler) { + SymfonyTestsListenerTrait::$previousErrorHandler = set_error_handler([SymfonyTestsListenerTrait::class, 'handleError']); + } + + SymfonyTestsListenerTrait::$expectedDeprecations[] = $message; + } +}