mirror of
https://github.com/pestphp/pest.git
synced 2026-03-09 17:27:22 +01:00
feat: --bail
This commit is contained in:
@ -23,8 +23,9 @@ final class BootSubscribers implements Bootstrapper
|
||||
private const SUBSCRIBERS = [
|
||||
Subscribers\EnsureConfigurationIsValid::class,
|
||||
Subscribers\EnsureConfigurationIsAvailable::class,
|
||||
Subscribers\EnsureTeamCityEnabled::class,
|
||||
Subscribers\EnsureIgnorableTestCasesAreIgnored::class,
|
||||
Subscribers\EnsureKernelDumpIsFlushed::class,
|
||||
Subscribers\EnsureTeamCityEnabled::class,
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
30
src/Plugins/Bail.php
Normal file
30
src/Plugins/Bail.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pest\Plugins;
|
||||
|
||||
use Pest\Contracts\Plugins\HandlesArguments;
|
||||
use Pest\Plugins\Concerns\HandleArguments;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class Bail implements HandlesArguments
|
||||
{
|
||||
use HandleArguments;
|
||||
|
||||
/**
|
||||
* Handles the arguments, adding the `--stop-on-defect` when the `--bail` argument is present.
|
||||
*/
|
||||
public function handleArguments(array $arguments): array
|
||||
{
|
||||
if ($this->hasArgument('--bail', $arguments)) {
|
||||
$arguments = $this->popArgument('--bail', $arguments);
|
||||
|
||||
$arguments = $this->pushArgument('--stop-on-defect', $arguments);
|
||||
}
|
||||
|
||||
return $arguments;
|
||||
}
|
||||
}
|
||||
@ -58,6 +58,8 @@ final class Help implements HandlesArguments
|
||||
'desc' => $description,
|
||||
] = $option;
|
||||
|
||||
assert(is_string($argument));
|
||||
|
||||
View::render('components.two-column-detail', [
|
||||
'left' => $this->colorizeOptions($argument),
|
||||
'right' => preg_replace(['/</', '/>/'], ['[', ']'], $description),
|
||||
@ -78,7 +80,7 @@ final class Help implements HandlesArguments
|
||||
*/
|
||||
private function colorizeOptions(string $argument): string
|
||||
{
|
||||
return preg_replace(
|
||||
return (string) preg_replace(
|
||||
['/</', '/>/', '/(-+[\w-]+)/'],
|
||||
['[', ']', '<fg=blue;options=bold>$1</>'],
|
||||
$argument
|
||||
@ -95,12 +97,12 @@ final class Help implements HandlesArguments
|
||||
/** @var array<string, array<int, array{arg: string, desc: string}>> $content */
|
||||
$content = $helpReflection->getConstant('HELP_TEXT');
|
||||
|
||||
$content['Configuration'] = [[
|
||||
$content['Configuration'] = [...[[
|
||||
'arg' => '--init',
|
||||
'desc' => 'Initialise a standard Pest configuration',
|
||||
], $content['Configuration']];
|
||||
]], ...$content['Configuration']];
|
||||
|
||||
$content['Selection'] = [
|
||||
$content['Selection'] = array_merge([
|
||||
[
|
||||
'arg' => '--todos',
|
||||
'desc' => 'Output to standard output the list of todos',
|
||||
@ -109,7 +111,7 @@ final class Help implements HandlesArguments
|
||||
'arg' => '--retry',
|
||||
'desc' => 'Run non-passing tests first and stop execution upon first error or failure',
|
||||
],
|
||||
] + $content['Selection'];
|
||||
], $content['Selection']);
|
||||
|
||||
$content['Reporting'] = [...$content['Reporting'], ...[
|
||||
[
|
||||
|
||||
42
src/Subscribers/EnsureIgnorableTestCasesAreIgnored.php
Normal file
42
src/Subscribers/EnsureIgnorableTestCasesAreIgnored.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pest\Subscribers;
|
||||
|
||||
use PHPUnit\Event\TestRunner\Started;
|
||||
use PHPUnit\Event\TestRunner\StartedSubscriber;
|
||||
use PHPUnit\Event\TestRunner\WarningTriggered;
|
||||
use PHPUnit\TestRunner\TestResult\Collector;
|
||||
use PHPUnit\TestRunner\TestResult\Facade;
|
||||
use ReflectionClass;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class EnsureIgnorableTestCasesAreIgnored implements StartedSubscriber
|
||||
{
|
||||
/**
|
||||
* Runs the subscriber.
|
||||
*/
|
||||
public function notify(Started $event): void
|
||||
{
|
||||
$reflection = new ReflectionClass(Facade::class);
|
||||
$property = $reflection->getProperty('collector');
|
||||
$property->setAccessible(true);
|
||||
$collector = $property->getValue();
|
||||
|
||||
assert($collector instanceof Collector);
|
||||
|
||||
$reflection = new ReflectionClass($collector);
|
||||
$property = $reflection->getProperty('testRunnerTriggeredWarningEvents');
|
||||
$property->setAccessible(true);
|
||||
|
||||
/** @var array<int, WarningTriggered> $testRunnerTriggeredWarningEvents */
|
||||
$testRunnerTriggeredWarningEvents = $property->getValue($collector);
|
||||
|
||||
$testRunnerTriggeredWarningEvents = array_values(array_filter($testRunnerTriggeredWarningEvents, fn (WarningTriggered $event): bool => $event->message() !== 'No tests found in class "Pest\TestCases\IgnorableTestCase".'));
|
||||
|
||||
$property->setValue($collector, $testRunnerTriggeredWarningEvents);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user