From a05684026e63cdc02089b72a3be76028d336b905 Mon Sep 17 00:00:00 2001 From: Fabio Ivona Date: Fri, 24 Mar 2023 19:00:38 +0100 Subject: [PATCH] wip --- overrides/Event/Value/ThrowableBuilder.php | 53 ++++++++++++++++++++++ src/Bootstrappers/BootOverrides.php | 1 + 2 files changed, 54 insertions(+) create mode 100644 overrides/Event/Value/ThrowableBuilder.php diff --git a/overrides/Event/Value/ThrowableBuilder.php b/overrides/Event/Value/ThrowableBuilder.php new file mode 100644 index 00000000..c2a0326e --- /dev/null +++ b/overrides/Event/Value/ThrowableBuilder.php @@ -0,0 +1,53 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace PHPUnit\Event\Code; + +use NunoMaduro\Collision\Contracts\CustomEditor; +use PHPUnit\Event\NoPreviousThrowableException; +use PHPUnit\Framework\Exception; +use PHPUnit\Util\Filter; +use PHPUnit\Util\ThrowableToStringMapper; + +/** + * @internal This class is not covered by the backward compatibility promise for PHPUnit + */ +final class ThrowableBuilder +{ + /** + * @throws Exception + * @throws NoPreviousThrowableException + */ + public static function from(\Throwable $t): Throwable + { + $previous = $t->getPrevious(); + + if ($previous !== null) { + $previous = self::from($previous); + } + + $trace = Filter::getFilteredStacktrace($t); + + if($t instanceof CustomEditor && $t->getCustomEditorFrame()){ + $frame = $t->getCustomEditorFrame(); + $file = $frame->getFile(); + $line = $frame->getLine(); + + $trace = "$file:$line\n$trace"; + } + + return new Throwable( + $t::class, + $t->getMessage(), + ThrowableToStringMapper::map($t), + $trace, + $previous + ); + } +} diff --git a/src/Bootstrappers/BootOverrides.php b/src/Bootstrappers/BootOverrides.php index e1489d7c..0fc1aee6 100644 --- a/src/Bootstrappers/BootOverrides.php +++ b/src/Bootstrappers/BootOverrides.php @@ -24,6 +24,7 @@ final class BootOverrides implements Bootstrapper 'TextUI/Command/WarmCodeCoverageCacheCommand.php', 'TextUI/Output/Default/ProgressPrinter/TestSkippedSubscriber.php', 'TextUI/TestSuiteFilterProcessor.php', + 'Event/Value/ThrowableBuilder.php', ]; /**