mirror of
https://github.com/pestphp/pest.git
synced 2026-03-07 00:07:22 +01:00
fix: no --dirty tests found
This commit is contained in:
23
src/Contracts/Panicable.php
Normal file
23
src/Contracts/Panicable.php
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Pest\Contracts;
|
||||||
|
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
interface Panicable
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Renders the panic on the given output.
|
||||||
|
*/
|
||||||
|
public function render(OutputInterface $output): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The exit code to be used.
|
||||||
|
*/
|
||||||
|
public function exitCode(): int;
|
||||||
|
}
|
||||||
38
src/Exceptions/NoDirtyTestsFound.php
Normal file
38
src/Exceptions/NoDirtyTestsFound.php
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Pest\Exceptions;
|
||||||
|
|
||||||
|
use InvalidArgumentException;
|
||||||
|
use NunoMaduro\Collision\Contracts\RenderlessEditor;
|
||||||
|
use NunoMaduro\Collision\Contracts\RenderlessTrace;
|
||||||
|
use Pest\Contracts\Panicable;
|
||||||
|
use Symfony\Component\Console\Exception\ExceptionInterface;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
final class NoDirtyTestsFound extends InvalidArgumentException implements ExceptionInterface, RenderlessEditor, RenderlessTrace, Panicable
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Renders the panic on the given output.
|
||||||
|
*/
|
||||||
|
public function render(OutputInterface $output): void
|
||||||
|
{
|
||||||
|
$output->writeln([
|
||||||
|
'',
|
||||||
|
' <fg=white;options=bold;bg=blue> INFO </> No "dirty" tests found.',
|
||||||
|
'',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The exit code to be used.
|
||||||
|
*/
|
||||||
|
public function exitCode(): int
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,26 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Pest\Exceptions;
|
|
||||||
|
|
||||||
use InvalidArgumentException;
|
|
||||||
use NunoMaduro\Collision\Contracts\RenderlessEditor;
|
|
||||||
use NunoMaduro\Collision\Contracts\RenderlessTrace;
|
|
||||||
use Symfony\Component\Console\Exception\ExceptionInterface;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
final class NoTestsFound extends InvalidArgumentException implements ExceptionInterface, RenderlessEditor, RenderlessTrace
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Creates a new Exception instance.
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
parent::__construct('No tests found.');
|
|
||||||
|
|
||||||
// ...
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -5,7 +5,7 @@ declare(strict_types=1);
|
|||||||
namespace Pest;
|
namespace Pest;
|
||||||
|
|
||||||
use Pest\Contracts\Bootstrapper;
|
use Pest\Contracts\Bootstrapper;
|
||||||
use Pest\Exceptions\NoTestsFound;
|
use Pest\Exceptions\NoDirtyTestsFound;
|
||||||
use Pest\Plugins\Actions\CallsAddsOutput;
|
use Pest\Plugins\Actions\CallsAddsOutput;
|
||||||
use Pest\Plugins\Actions\CallsBoot;
|
use Pest\Plugins\Actions\CallsBoot;
|
||||||
use Pest\Plugins\Actions\CallsShutdown;
|
use Pest\Plugins\Actions\CallsShutdown;
|
||||||
@ -87,7 +87,7 @@ final class Kernel
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$this->application->run($args);
|
$this->application->run($args);
|
||||||
} catch (NoTestsFound) {
|
} catch (NoDirtyTestsFound) {
|
||||||
$this->output->writeln([
|
$this->output->writeln([
|
||||||
'',
|
'',
|
||||||
' <fg=white;options=bold;bg=blue> INFO </> No tests found.',
|
' <fg=white;options=bold;bg=blue> INFO </> No tests found.',
|
||||||
|
|||||||
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -6,7 +6,8 @@ namespace Pest\TestCaseFilters;
|
|||||||
|
|
||||||
use Pest\Contracts\TestCaseFilter;
|
use Pest\Contracts\TestCaseFilter;
|
||||||
use Pest\Exceptions\MissingDependency;
|
use Pest\Exceptions\MissingDependency;
|
||||||
use Pest\Exceptions\NoTestsFound;
|
use Pest\Exceptions\NoDirtyTestsFound;
|
||||||
|
use Pest\Panic;
|
||||||
use Pest\TestSuite;
|
use Pest\TestSuite;
|
||||||
use Symfony\Component\Process\Process;
|
use Symfony\Component\Process\Process;
|
||||||
|
|
||||||
@ -66,7 +67,7 @@ final class GitDirtyTestCaseFilter implements TestCaseFilter
|
|||||||
$dirtyFiles = array_values($dirtyFiles);
|
$dirtyFiles = array_values($dirtyFiles);
|
||||||
|
|
||||||
if ($dirtyFiles === []) {
|
if ($dirtyFiles === []) {
|
||||||
throw new NoTestsFound();
|
Panic::with(new NoDirtyTestsFound());
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->changedFiles = $dirtyFiles;
|
$this->changedFiles = $dirtyFiles;
|
||||||
|
|||||||
Reference in New Issue
Block a user