Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb253eb6

Browse files
karsernicolas-grekas
authored andcommitted
[PhpUnitBridge] fixed PHPUnit 8.3 compatibility: method handleError was renamed to __invoke
1 parent2f97ab1 commitb253eb6

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
namespaceSymfony\Bridge\PhpUnit;
1313

14+
usePHPUnit\Framework\TestResult;
15+
usePHPUnit\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
constMODE_DISABLED ='disabled';
2427

2528
privatestatic$isRegistered =false;
29+
privatestatic$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(ErrorHandler::class,'__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 ($oldErrorHandlerinstanceof 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+
publicstaticfunctiongetPhpUnitErrorHandler()
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+
returnnewErrorHandler(
314+
$frame['object']->getConvertDeprecationsToExceptions(),
315+
$frame['object']->getConvertErrorsToExceptions(),
316+
$frame['object']->getConvertNoticesToExceptions(),
317+
$frame['object']->getConvertWarningsToExceptions()
318+
);
319+
}
320+
}
321+
322+
returnfunction () {returnfalse; };
323+
}
324+
303325
/**
304326
* Returns true if STDOUT is defined and supports colorization.
305327
*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp