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
{
@@ -341,16 +342,23 @@ private function displayDeprecations($groups, $configuration, $isFailing)
341
342
342
343
private static function getPhpUnitErrorHandler ()
343
344
{
344
- if (!isset (self ::$ isAtLeastPhpUnit83 )) {
345
- self ::$ isAtLeastPhpUnit83 = class_exists (ErrorHandler::class) && method_exists (ErrorHandler::class, '__invoke ' );
345
+ if (!$ eh = self ::$ errorHandler ) {
346
+ if (class_exists (Handler::class)) {
347
+ $ eh = self ::$ errorHandler = Handler::class;
348
+ } elseif (method_exists (ErrorHandler::class, '__invoke ' )) {
349
+ $ eh = self ::$ errorHandler = ErrorHandler::class;
350
+ } else {
351
+ return self ::$ errorHandler = 'PHPUnit\Util\ErrorHandler::handleError ' ;
352
+ }
346
353
}
347
- if (!self ::$ isAtLeastPhpUnit83 ) {
348
- return 'PHPUnit\Util\ErrorHandler::handleError ' ;
354
+
355
+ if ('PHPUnit\Util\ErrorHandler::handleError ' === $ eh ) {
356
+ return $ eh ;
349
357
}
350
358
351
359
foreach (debug_backtrace (\DEBUG_BACKTRACE_PROVIDE_OBJECT | \DEBUG_BACKTRACE_IGNORE_ARGS ) as $ frame ) {
352
360
if (isset ($ frame ['object ' ]) && $ frame ['object ' ] instanceof TestResult) {
353
- return new ErrorHandler (
361
+ return new $ eh (
354
362
$ frame ['object ' ]->getConvertDeprecationsToExceptions (),
355
363
$ frame ['object ' ]->getConvertErrorsToExceptions (),
356
364
$ frame ['object ' ]->getConvertNoticesToExceptions (),
0 commit comments