mirror of
https://github.com/pestphp/pest.git
synced 2026-03-10 09:47:23 +01:00
fix: no --dirty tests found
This commit is contained in:
60
src/Panic.php
Normal file
60
src/Panic.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pest;
|
||||
|
||||
use NunoMaduro\Collision\Writer;
|
||||
use Pest\Support\Container;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Throwable;
|
||||
use Whoops\Exception\Inspector;
|
||||
|
||||
final class Panic
|
||||
{
|
||||
/**
|
||||
* Creates a new Panic instance.
|
||||
*/
|
||||
private function __construct(
|
||||
private readonly Throwable $throwable
|
||||
) {
|
||||
// ...
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new Panic instance, and exits the application.
|
||||
*/
|
||||
public static function with(Throwable $throwable): never
|
||||
{
|
||||
$panic = new self($throwable);
|
||||
|
||||
$panic->handle();
|
||||
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the panic.
|
||||
*/
|
||||
private function handle(): void
|
||||
{
|
||||
/** @var OutputInterface $output */
|
||||
$output = Container::getInstance()->get(OutputInterface::class);
|
||||
|
||||
if ($this->throwable instanceof Contracts\Panicable) {
|
||||
$this->throwable->render($output);
|
||||
|
||||
exit($this->throwable->exitCode());
|
||||
}
|
||||
|
||||
$writer = new Writer(null, $output);
|
||||
|
||||
$inspector = new Inspector($this->throwable);
|
||||
|
||||
$output->writeln('');
|
||||
$writer->write($inspector);
|
||||
$output->writeln('');
|
||||
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user