Skip to content

Commit

Permalink
Fixed PHPUnit 8.3 incompatibility: method handleError was renamed to …
Browse files Browse the repository at this point in the history
…__invoke
  • Loading branch information
karser committed Aug 2, 2019
1 parent 8f1d9d2 commit 0865fc4
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php
Expand Up @@ -49,6 +49,7 @@ class DeprecationErrorHandler

private static $isRegistered = false;
private static $utilPrefix;
private static $isHandlerInvokable;

/**
* Registers and configures the deprecation handler.
Expand All @@ -73,14 +74,16 @@ 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']);

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);
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 0865fc4

Please sign in to comment.