This commit is contained in:
Fabio Ivona
2023-03-24 19:00:38 +01:00
parent cc6bd59df9
commit a05684026e
2 changed files with 54 additions and 0 deletions

View File

@ -0,0 +1,53 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* 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
);
}
}

View File

@ -24,6 +24,7 @@ final class BootOverrides implements Bootstrapper
'TextUI/Command/WarmCodeCoverageCacheCommand.php', 'TextUI/Command/WarmCodeCoverageCacheCommand.php',
'TextUI/Output/Default/ProgressPrinter/TestSkippedSubscriber.php', 'TextUI/Output/Default/ProgressPrinter/TestSkippedSubscriber.php',
'TextUI/TestSuiteFilterProcessor.php', 'TextUI/TestSuiteFilterProcessor.php',
'Event/Value/ThrowableBuilder.php',
]; ];
/** /**