8000 [PhpUnitBridge] fixed PHPUnit 8.3 compatibility: method handleError w… · symfony/symfony@0c9539f · GitHub
[go: up one dir, main page]

Skip to content

Commit 0c9539f

Browse files
karsernicolas-grekas
authored andcommitted
[PhpUnitBridge] fixed PHPUnit 8.3 compatibility: method handleError was renamed to __invoke
1 parent 2f97ab1 commit 0c9539f

File tree

1 file changed

+31
-9
lines changed

1 file changed

+31
-9
lines changed

src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
namespace Symfony\Bridge\PhpUnit;
1313

14+
use PHPUnit\Framework\TestResult;
15+
use PHPUnit\Util\ErrorHandler;
16+
1417
/**
1518
* Catch deprecation notices and print a summary report at the end of the test suite.
1619
*
@@ -23,6 +26,7 @@ class DeprecationErrorHandler
2326
const MODE_DISABLED = 'disabled';
2427

2528
private static $isRegistered = false;
29+
private static $isAtLeastPhpUnit83;
2630

2731
/**
2832
* Registers and configures the deprecation handler.
@@ -44,6 +48,7 @@ public static function register($mode = 0)
4448
}
4549

4650
$UtilPrefix = class_exists('PHPUnit_Util_ErrorHandler') ? 'PHPUnit_Util_' : 'PHPUnit\Util\\';
51+
self::$isAtLeastPhpUnit83 = method_exists('PHPUnit\Util\ErrorHandler', '__invoke');
4752

4853
$getMode = function () use ($mode) {
4954
static $memoizedMode = false;
@@ -106,9 +111,7 @@ public static function register($mode = 0)
106111
);
107112
$deprecationHandler = function ($type, $msg, $file, $line, $context = array()) use (&$deprecations, $getMode, $UtilPrefix, $inVendors) {
108113
if ((E_USER_DEPRECATED !== $type && E_DEPRECATED !== $type) || DeprecationErrorHandler::MODE_DISABLED === $mode = $getMode()) {
109-
$ErrorHandler = $UtilPrefix.'ErrorHandler';
110-
111-
return $ErrorHandler::handleError($type, $msg, $file, $line, $context);
114+
return \call_user_func(DeprecationErrorHandler::getPhpUnitErrorHandler(), $type, $msg, $file, $line, $context);
112115
}
113116

114117
$trace = debug_backtrace();
@@ -183,7 +186,7 @@ public static function register($mode = 0)
183186

184187
if (null !== $oldErrorHandler) {
185188
restore_error_handler();
186-
if (array($UtilPrefix.'ErrorHandler', 'handleError') === $oldErrorHandler) {
189+
if ($oldErrorHandler instanceof ErrorHandler || array($UtilPrefix.'ErrorHandler', 'handleError') === $oldErrorHandler) {
187190
restore_error_handler();
188191
self::register($mode);
189192
}
@@ -285,12 +288,8 @@ public static function collectDeprecations($outputFile)
285288
if ($previousErrorHandler) {
286289
return $previousErrorHandler($type, $msg, $file, $line, $context);
287290
}
288-
static $autoload = true;
289291

290-
$ErrorHandler = class_exists('PHPUnit_Util_ErrorHandler', $autoload) ? 'PHPUnit_Util_ErrorHandler' : 'PHPUnit\Util\ErrorHandler';
291-
$autoload = false;
292-
293-
return $ErrorHandler::handleError($type, $msg, $file, $line, $context);
292+
return \call_user_func(DeprecationErrorHandler::getPhpUnitErrorHandler(), $type, $msg, $file, $line, $context);
294293
}
295294
$deprecations[] = array(error_reporting(), $msg, $file);
296295
});
@@ -300,6 +299,29 @@ public static function collectDeprecations($outputFile)
300299
});
301300
}
302301

302+
/**
303+
* @internal
304+
*/
305+
public static function getPhpUnitErrorHandler()
306+
{
307+
if (!self::$isAtLeastPhpUnit83) {
308+
return (class_exists('PHPUnit_Util_ErrorHandler', false) ? 'PHPUnit_Util_' : 'PHPUnit\Util\\').'ErrorHandler::handleError';
309+
}
310+
311+
foreach (debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT | DEBUG_BACKTRACE_IGNORE_ARGS) as $frame) {
312+
if (isset($frame['object']) && $frame['object'] instanceof TestResult) {
313+
return new ErrorHandler(
314+
$frame['object']->getConvertDeprecationsToExceptions(),
315+
$frame['object']->getConvertErrorsToExceptions(),
316+
$frame['object']->getConvertNoticesToExceptions(),
317+
$frame['object']->getConvertWarningsToExceptions()
318+
);
319+
}
320+
}
321+
322+
return function () { return false; };
323+
}
324+
303325
/**
304326
* Returns true if STDOUT is defined and supports colorization.
305327
*

0 commit comments

Comments
 (0)
0