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 ;
@@ -38,7 +39,7 @@ class DeprecationErrorHandler
38
39
private $ deprecationGroups = [];
39
40
40
41
private static $ isRegistered = false ;
41
- private static $ isAtLeastPhpUnit83 ;
42
+ private static $ errorHandler ;
42
43
43
44
public function __construct ()
44
45
{
@@ -347,16 +348,23 @@ private function displayDeprecations($groups, $configuration, $isFailing)
347
348
348
349
private static function getPhpUnitErrorHandler ()
349
350
{
350
- if (!isset (self ::$ isAtLeastPhpUnit83 )) {
351
- self ::$ isAtLeastPhpUnit83 = class_exists (ErrorHandler::class) && method_exists (ErrorHandler::class, '__invoke ' );
351
+ if (!$ eh = self ::$ errorHandler ) {
352
+ if (class_exists (Handler::class)) {
353
+ $ eh = self ::$ errorHandler = Handler::class;
354
+ } elseif (method_exists (ErrorHandler::class, '__invoke ' )) {
355
+ $ eh = self ::$ errorHandler = ErrorHandler::class;
356
+ } else {
357
+ return self ::$ errorHandler = 'PHPUnit\Util\ErrorHandler::handleError ' ;
358
+ }
352
359
}
353
- if (!self ::$ isAtLeastPhpUnit83 ) {
354
- return 'PHPUnit\Util\ErrorHandler::handleError ' ;
360
+
361
+ if ('PHPUnit\Util\ErrorHandler::handleError ' === $ eh ) {
362
+ return $ eh ;
355
363
}
356
364
357
365
foreach (debug_backtrace (\DEBUG_BACKTRACE_PROVIDE_OBJECT | \DEBUG_BACKTRACE_IGNORE_ARGS ) as $ frame ) {
358
366
if (isset ($ frame ['object ' ]) && $ frame ['object ' ] instanceof TestResult) {
359
- return new ErrorHandler (
367
+ return new $ eh (
360
368
$ frame ['object ' ]->getConvertDeprecationsToExceptions (),
361
369
$ frame ['object ' ]->getConvertErrorsToExceptions (),
362
370
$ frame ['object ' ]->getConvertNoticesToExceptions (),
0 commit comments