|
12 | 12 | namespace Symfony\Bridge\PhpUnit;
|
13 | 13 |
|
14 | 14 | use PHPUnit\Framework\TestResult;
|
| 15 | +use PHPUnit\Util\Error\Handler; |
15 | 16 | use PHPUnit\Util\ErrorHandler;
|
16 | 17 | use Symfony\Bridge\PhpUnit\DeprecationErrorHandler\Configuration;
|
17 | 18 | use Symfony\Bridge\PhpUnit\DeprecationErrorHandler\Deprecation;
|
@@ -51,7 +52,7 @@ class DeprecationErrorHandler
|
51 | 52 | ];
|
52 | 53 |
|
53 | 54 | private static $isRegistered = false;
|
54 |
| - private static $isAtLeastPhpUnit83; |
| 55 | + private static $errorHandler; |
55 | 56 |
|
56 | 57 | /**
|
57 | 58 | * Registers and configures the deprecation handler.
|
@@ -335,16 +336,23 @@ private function displayDeprecations($groups, $configuration)
|
335 | 336 |
|
336 | 337 | private static function getPhpUnitErrorHandler()
|
337 | 338 | {
|
338 |
| - if (!isset(self::$isAtLeastPhpUnit83)) { |
339 |
| - self::$isAtLeastPhpUnit83 = class_exists(ErrorHandler::class) && method_exists(ErrorHandler::class, '__invoke'); |
| 339 | + if (!$eh = self::$errorHandler) { |
| 340 | + if (class_exists(Handler::class)) { |
| 341 | + $eh = self::$errorHandler = Handler::class; |
| 342 | + } elseif (method_exists(ErrorHandler::class, '__invoke')) { |
| 343 | + $eh = self::$errorHandler = ErrorHandler::class; |
| 344 | + } else { |
| 345 | + return self::$errorHandler = 'PHPUnit\Util\ErrorHandler::handleError'; |
| 346 | + } |
340 | 347 | }
|
341 |
| - if (!self::$isAtLeastPhpUnit83) { |
342 |
| - return 'PHPUnit\Util\ErrorHandler::handleError'; |
| 348 | + |
| 349 | + if ('PHPUnit\Util\ErrorHandler::handleError' === $eh) { |
| 350 | + return $eh; |
343 | 351 | }
|
344 | 352 |
|
345 | 353 | foreach (debug_backtrace(\DEBUG_BACKTRACE_PROVIDE_OBJECT | \DEBUG_BACKTRACE_IGNORE_ARGS) as $frame) {
|
346 | 354 | if (isset($frame['object']) && $frame['object'] instanceof TestResult) {
|
347 |
| - return new ErrorHandler( |
| 355 | + return new $eh( |
348 | 356 | $frame['object']->getConvertDeprecationsToExceptions(),
|
349 | 357 | $frame['object']->getConvertErrorsToExceptions(),
|
350 | 358 | $frame['object']->getConvertNoticesToExceptions(),
|
|
0 commit comments