From e6742f58fad1e9548a9557cdde0db674a23d4b88 Mon Sep 17 00:00:00 2001 From: HypeMC Date: Sat, 25 May 2024 13:44:26 +0200 Subject: [PATCH] [PhpUnitBridge] Fix error handler triggered outside of tests --- DeprecationErrorHandler.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/DeprecationErrorHandler.php b/DeprecationErrorHandler.php index 05c67b7..95312e2 100644 --- a/DeprecationErrorHandler.php +++ b/DeprecationErrorHandler.php @@ -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; + }; } }