Skip to content

Commit

Permalink
bug #57110 [PhpUnitBridge] Fix error handler triggered outside of tes…
Browse files Browse the repository at this point in the history
…ts (HypeMC)

This PR was merged into the 5.4 branch.

Discussion
----------

[PhpUnitBridge] Fix error handler triggered outside of tests

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | Fix #57071
| License       | MIT

The error handler should be invoked only if the error occurred inside a test.

Commits
-------

348f11a867 [PhpUnitBridge] Fix error handler triggered outside of tests
  • Loading branch information
fabpot committed Jun 4, 2024
2 parents 875f703 + e6742f5 commit bbd310b
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 @@ -368,22 +368,26 @@ private static function getPhpUnitErrorHandler()

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 bbd310b

Please sign in to comment.