From 0865fc42faf799aa1c25e286a4f55a942843a63b Mon Sep 17 00:00:00 2001 From: karser Date: Fri, 2 Aug 2019 22:29:48 +0300 Subject: [PATCH] Fixed PHPUnit 8.3 incompatibility: method handleError was renamed to __invoke --- .../PhpUnit/DeprecationErrorHandler.php | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php index e059fe2a9d995..e900ff6f7119b 100644 --- a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php +++ b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php @@ -49,6 +49,7 @@ class DeprecationErrorHandler private static $isRegistered = false; private static $utilPrefix; + private static $isHandlerInvokable; /** * Registers and configures the deprecation handler. @@ -73,6 +74,7 @@ public static function register($mode = 0) } self::$utilPrefix = class_exists('PHPUnit_Util_ErrorHandler') ? 'PHPUnit_Util_' : 'PHPUnit\Util\\'; + self::$isHandlerInvokable = method_exists(self::$utilPrefix.'ErrorHandler', '__invoke'); $handler = new self(); $oldErrorHandler = set_error_handler([$handler, 'handleError']); @@ -80,7 +82,8 @@ public static function register($mode = 0) if (null !== $oldErrorHandler) { restore_error_handler(); - if ([self::$utilPrefix.'ErrorHandler', 'handleError'] === $oldErrorHandler) { + $handlerMethod = self::$isHandlerInvokable ? '__invoke' : 'handleError'; + if ([self::$utilPrefix.'ErrorHandler', $handlerMethod] === $oldErrorHandler) { restore_error_handler(); self::register($mode); } @@ -116,15 +119,25 @@ public static function collectDeprecations($outputFile) }); } + private function callPhpUnitErrorHandler($type, $msg, $file, $line, $context) + { + $ErrorHandler = self::$utilPrefix.'ErrorHandler'; + if (self::$isHandlerInvokable) { + $object = new $ErrorHandler($convertDeprecationsToExceptions = true, $convertErrorsToExceptions = true, $convertNoticesToExceptions = true, $convertWarningsToExceptions = true); + + return $object($type, $msg, $file, $line, $context); + } + + return $ErrorHandler::handleError($type, $msg, $file, $line, $context); + } + /** * @internal */ public function handleError($type, $msg, $file, $line, $context = []) { if ((E_USER_DEPRECATED !== $type && E_DEPRECATED !== $type) || !$this->getConfiguration()->isEnabled()) { - $ErrorHandler = self::$utilPrefix.'ErrorHandler'; - - return $ErrorHandler::handleError($type, $msg, $file, $line, $context); + return $this->callPhpUnitErrorHandler($type, $msg, $file, $line, $context); } $deprecation = new Deprecation($msg, debug_backtrace(), $file);