diff --git a/src/KernelDump.php b/src/KernelDump.php index 6dfb0019..ebf1ad3d 100644 --- a/src/KernelDump.php +++ b/src/KernelDump.php @@ -43,7 +43,7 @@ final class KernelDump @ob_clean(); // @phpstan-ignore-line if ($this->buffer !== '') { - $this->flush('INFO'); + $this->flush(); } } @@ -52,36 +52,42 @@ final class KernelDump */ public function shutdown(): void { - @ob_clean(); // @phpstan-ignore-line - - if ($this->buffer !== '') { - $this->flush('ERROR'); - } + $this->disable(); } /** * Flushes the buffer. */ - private function flush(string $type): void + private function flush(): void { View::renderUsing($this->output); - if ($this->isOpeningHeadline($this->buffer)) { $this->buffer = implode(PHP_EOL, array_slice(explode(PHP_EOL, $this->buffer), 2)); } + $type = 'INFO'; + if ($this->isInternalError($this->buffer)) { + $type = 'ERROR'; $this->buffer = str_replace('An error occurred inside PHPUnit.', '', $this->buffer); } $this->buffer = trim($this->buffer); $this->buffer = rtrim($this->buffer, '.').'.'; + $lines = explode(PHP_EOL, $this->buffer); + + $lines = array_reverse($lines); + $firstLine = array_pop($lines); + $lines = array_reverse($lines); + View::render('components.badge', [ 'type' => $type, - 'content' => $this->buffer, + 'content' => $firstLine, ]); + $this->output->writeln($lines); + $this->buffer = ''; } diff --git a/src/Panic.php b/src/Panic.php index a14bf428..4b198c7c 100644 --- a/src/Panic.php +++ b/src/Panic.php @@ -6,6 +6,7 @@ namespace Pest; use NunoMaduro\Collision\Writer; use Pest\Support\Container; +use Symfony\Component\Console\Output\ConsoleOutput; use Symfony\Component\Console\Output\OutputInterface; use Throwable; use Whoops\Exception\Inspector; @@ -39,7 +40,11 @@ final class Panic private function handle(): void { /** @var OutputInterface $output */ - $output = Container::getInstance()->get(OutputInterface::class); + try { + $output = Container::getInstance()->get(OutputInterface::class); + } catch (Throwable) { + $output = new ConsoleOutput(); + } if ($this->throwable instanceof Contracts\Panicable) { $this->throwable->render($output); @@ -51,7 +56,6 @@ final class Panic $inspector = new Inspector($this->throwable); - $output->writeln(''); $writer->write($inspector); $output->writeln(''); diff --git a/src/TestSuite.php b/src/TestSuite.php index 68bc842f..1c4297f6 100644 --- a/src/TestSuite.php +++ b/src/TestSuite.php @@ -91,7 +91,7 @@ final class TestSuite } if (! self::$instance instanceof self) { - throw new InvalidPestCommand(); + Panic::with(new InvalidPestCommand()); } return self::$instance;