Skip to content

Commit 0865fc4

Browse files
committed
Fixed PHPUnit 8.3 incompatibility: method handleError was renamed to __invoke
1 parent 8f1d9d2 commit 0865fc4

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class DeprecationErrorHandler
4949

5050
private static $isRegistered = false;
5151
private static $utilPrefix;
52+
private static $isHandlerInvokable;
5253

5354
/**
5455
* Registers and configures the deprecation handler.
@@ -73,14 +74,16 @@ public static function register($mode = 0)
7374
}
7475

7576
self::$utilPrefix = class_exists('PHPUnit_Util_ErrorHandler') ? 'PHPUnit_Util_' : 'PHPUnit\Util\\';
77+
self::$isHandlerInvokable = method_exists(self::$utilPrefix.'ErrorHandler', '__invoke');
7678

7779
$handler = new self();
7880
$oldErrorHandler = set_error_handler([$handler, 'handleError']);
7981

8082
if (null !== $oldErrorHandler) {
8183
restore_error_handler();
8284

83-
if ([self::$utilPrefix.'ErrorHandler', 'handleError'] === $oldErrorHandler) {
85+
$handlerMethod = self::$isHandlerInvokable ? '__invoke' : 'handleError';
86+
if ([self::$utilPrefix.'ErrorHandler', $handlerMethod] === $oldErrorHandler) {
8487
restore_error_handler();
8588
self::register($mode);
8689
}
@@ -116,15 +119,25 @@ public static function collectDeprecations($outputFile)
116119
});
117120
}
118121

122+
private function callPhpUnitErrorHandler($type, $msg, $file, $line, $context)
123+
{
124+
$ErrorHandler = self::$utilPrefix.'ErrorHandler';
125+
if (self::$isHandlerInvokable) {
126+
$object = new $ErrorHandler($convertDeprecationsToExceptions = true, $convertErrorsToExceptions = true, $convertNoticesToExceptions = true, $convertWarningsToExceptions = true);
127+
128+
return $object($type, $msg, $file, $line, $context);
129+
}
130+
131+
return $ErrorHandler::handleError($type, $msg, $file, $line, $context);
132+
}
133+
119134
/**
120135
* @internal
121136
*/
122137
public function handleError($type, $msg, $file, $line, $context = [])
123138
{
124139
if ((E_USER_DEPRECATED !== $type && E_DEPRECATED !== $type) || !$this->getConfiguration()->isEnabled()) {
125-
$ErrorHandler = self::$utilPrefix.'ErrorHandler';
126-
127-
return $ErrorHandler::handleError($type, $msg, $file, $line, $context);
140+
return $this->callPhpUnitErrorHandler($type, $msg, $file, $line, $context);
128141
}
129142

130143
$deprecation = new Deprecation($msg, debug_backtrace(), $file);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy