mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
Merge pull request #754 from fabio-ivona/collision-custom-editor-support
[2.x] Collision custom editor support
This commit is contained in:
@ -19,7 +19,7 @@
|
|||||||
"require": {
|
"require": {
|
||||||
"php": "^8.1.0",
|
"php": "^8.1.0",
|
||||||
"brianium/paratest": "^7.1.2",
|
"brianium/paratest": "^7.1.2",
|
||||||
"nunomaduro/collision": "^7.3.3",
|
"nunomaduro/collision": "^v7.x-dev",
|
||||||
"nunomaduro/termwind": "^1.15.1",
|
"nunomaduro/termwind": "^1.15.1",
|
||||||
"pestphp/pest-plugin": "^2.0.1",
|
"pestphp/pest-plugin": "^2.0.1",
|
||||||
"pestphp/pest-plugin-arch": "^2.0.2",
|
"pestphp/pest-plugin-arch": "^2.0.2",
|
||||||
|
|||||||
55
overrides/Event/Value/ThrowableBuilder.php
Normal file
55
overrides/Event/Value/ThrowableBuilder.php
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
<?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\RenderableOnCollisionEditor;
|
||||||
|
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 RenderableOnCollisionEditor && $frame = $t->toCollisionEditor()) {
|
||||||
|
$file = $frame->getFile();
|
||||||
|
$line = $frame->getLine();
|
||||||
|
|
||||||
|
$trace = "$file:$line\n$trace";
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Throwable(
|
||||||
|
$t::class,
|
||||||
|
$t->getMessage(),
|
||||||
|
ThrowableToStringMapper::map($t),
|
||||||
|
$trace,
|
||||||
|
$previous
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
28
tests/Unit/Overrides/ThrowableBuilder.php
Normal file
28
tests/Unit/Overrides/ThrowableBuilder.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use NunoMaduro\Collision\Contracts\RenderableOnCollisionEditor;
|
||||||
|
use PHPUnit\Event\Code\ThrowableBuilder;
|
||||||
|
use Whoops\Exception\Frame;
|
||||||
|
|
||||||
|
test('collision editor can be added to the stack trace', function () {
|
||||||
|
$exception = new class extends Exception implements RenderableOnCollisionEditor
|
||||||
|
{
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct('test exception');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function toCollisionEditor(): Frame
|
||||||
|
{
|
||||||
|
return new Frame([
|
||||||
|
'file' => __DIR__.'/../../Pest.php',
|
||||||
|
'line' => 5,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(ThrowableBuilder::from($exception))
|
||||||
|
->stackTrace()->toStartWith('/data/projects/open-source/pest/tests/Unit/Overrides/../../Pest.php:5')
|
||||||
|
->and(ThrowableBuilder::from(new Exception('test')))
|
||||||
|
->stackTrace()->toStartWith('/data/projects/open-source/pest/tests/Unit/Overrides/ThrowableBuilder.php:26');
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user