Skip to content

Commit

Permalink
Merge branch '7.0' into 7.1
Browse files Browse the repository at this point in the history
* 7.0:
  [PhpUnitBridge] Fix error handler triggered outside of tests
  • Loading branch information
fabpot committed Jun 4, 2024
2 parents f33b3da + 2a7e8d2 commit 3e1cb8c
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions DeprecationErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,22 +367,26 @@ private static function getPhpUnitErrorHandler(): callable

if ('PHPUnit\Util\ErrorHandler::handleError' === $eh) {
return $eh;
} elseif (ErrorHandler::class === $eh) {
return function (int $errorNumber, string $errorString, string $errorFile, int $errorLine) {
ErrorHandler::instance()($errorNumber, $errorString, $errorFile, $errorLine);

return true;
};
}

foreach (debug_backtrace(\DEBUG_BACKTRACE_PROVIDE_OBJECT | \DEBUG_BACKTRACE_IGNORE_ARGS) as $frame) {
if (isset($frame['object']) && $frame['object'] instanceof TestResult) {
if (!isset($frame['object'])) {
continue;
}

if ($frame['object'] instanceof TestResult) {
return new $eh(
$frame['object']->getConvertDeprecationsToExceptions(),
$frame['object']->getConvertErrorsToExceptions(),
$frame['object']->getConvertNoticesToExceptions(),
$frame['object']->getConvertWarningsToExceptions()
);
} elseif (ErrorHandler::class === $eh && $frame['object'] instanceof TestCase) {
return function (int $errorNumber, string $errorString, string $errorFile, int $errorLine) {
ErrorHandler::instance()($errorNumber, $errorString, $errorFile, $errorLine);

return true;
};
}
}

Expand Down

0 comments on commit 3e1cb8c

Please sign in to comment.