New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PhpUnitBridge] fixed PHPUnit 8.3 compatibility: method handleError was renamed to __invoke #32933
Merged
nicolas-grekas
merged 1 commit into
symfony:3.4
from
karser:phpunit83-errorhandler-fix-stacktrace
Aug 5, 2019
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,9 @@ | |
|
||
namespace Symfony\Bridge\PhpUnit; | ||
|
||
use PHPUnit\Framework\TestResult; | ||
use PHPUnit\Util\ErrorHandler; | ||
|
||
/** | ||
* Catch deprecation notices and print a summary report at the end of the test suite. | ||
* | ||
|
@@ -23,6 +26,7 @@ class DeprecationErrorHandler | |
const MODE_DISABLED = 'disabled'; | ||
|
||
private static $isRegistered = false; | ||
private static $isAtLeastPhpUnit83; | ||
|
||
/** | ||
* Registers and configures the deprecation handler. | ||
|
@@ -44,6 +48,7 @@ public static function register($mode = 0) | |
} | ||
|
||
$UtilPrefix = class_exists('PHPUnit_Util_ErrorHandler') ? 'PHPUnit_Util_' : 'PHPUnit\Util\\'; | ||
self::$isAtLeastPhpUnit83 = method_exists('PHPUnit\Util\ErrorHandler', '__invoke'); | ||
|
||
$getMode = function () use ($mode) { | ||
static $memoizedMode = false; | ||
|
@@ -106,9 +111,7 @@ public static function register($mode = 0) | |
); | ||
$deprecationHandler = function ($type, $msg, $file, $line, $context = array()) use (&$deprecations, $getMode, $UtilPrefix, $inVendors) { | ||
if ((E_USER_DEPRECATED !== $type && E_DEPRECATED !== $type) || DeprecationErrorHandler::MODE_DISABLED === $mode = $getMode()) { | ||
$ErrorHandler = $UtilPrefix.'ErrorHandler'; | ||
|
||
return $ErrorHandler::handleError($type, $msg, $file, $line, $context); | ||
return \call_user_func(DeprecationErrorHandler::getPhpUnitErrorHandler(), $type, $msg, $file, $line, $context); | ||
} | ||
|
||
$trace = debug_backtrace(); | ||
|
@@ -183,7 +186,7 @@ public static function register($mode = 0) | |
|
||
if (null !== $oldErrorHandler) { | ||
restore_error_handler(); | ||
if (array($UtilPrefix.'ErrorHandler', 'handleError') === $oldErrorHandler) { | ||
if ($oldErrorHandler instanceof ErrorHandler || array($UtilPrefix.'ErrorHandler', 'handleError') === $oldErrorHandler) { | ||
restore_error_handler(); | ||
self::register($mode); | ||
} | ||
|
@@ -285,12 +288,8 @@ public static function collectDeprecations($outputFile) | |
if ($previousErrorHandler) { | ||
return $previousErrorHandler($type, $msg, $file, $line, $context); | ||
} | ||
static $autoload = true; | ||
|
||
$ErrorHandler = class_exists('PHPUnit_Util_ErrorHandler', $autoload) ? 'PHPUnit_Util_ErrorHandler' : 'PHPUnit\Util\ErrorHandler'; | ||
$autoload = false; | ||
|
||
return $ErrorHandler::handleError($type, $msg, $file, $line, $context); | ||
return \call_user_func(DeprecationErrorHandler::getPhpUnitErrorHandler(), $type, $msg, $file, $line, $context); | ||
} | ||
$deprecations[] = array(error_reporting(), $msg, $file); | ||
}); | ||
|
@@ -300,6 +299,29 @@ public static function collectDeprecations($outputFile) | |
}); | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
public static function getPhpUnitErrorHandler() | ||
{ | ||
if (!self::$isAtLeastPhpUnit83) { | ||
return (class_exists('PHPUnit_Util_ErrorHandler', false) ? 'PHPUnit_Util_' : 'PHPUnit\Util\\').'ErrorHandler::handleError'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nvm. Didn't notice that version were 3.4 |
||
} | ||
|
||
foreach (debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT | DEBUG_BACKTRACE_IGNORE_ARGS) as $frame) { | ||
if (isset($frame['object']) && $frame['object'] instanceof TestResult) { | ||
return new ErrorHandler( | ||
$frame['object']->getConvertDeprecationsToExceptions(), | ||
$frame['object']->getConvertErrorsToExceptions(), | ||
$frame['object']->getConvertNoticesToExceptions(), | ||
$frame['object']->getConvertWarningsToExceptions() | ||
); | ||
} | ||
} | ||
|
||
return function () { return false; }; | ||
} | ||
|
||
/** | ||
* Returns true if STDOUT is defined and supports colorization. | ||
* | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ErrorHandler::class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nvm. Didn't notice that version were 3.4