mirror of
https://github.com/pestphp/pest.git
synced 2026-03-07 08:17:22 +01:00
Add errors-only flag
This commit is contained in:
@ -27,6 +27,20 @@ final class Coverage implements AddsOutput, HandlesArguments
|
||||
*/
|
||||
private const MIN_OPTION = 'min';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private const ERRORS_ONLY_OPTION = 'errors-only';
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
private const ALLOWED_OPTIONS = [
|
||||
self::COVERAGE_OPTION,
|
||||
self::MIN_OPTION,
|
||||
self::ERRORS_ONLY_OPTION,
|
||||
];
|
||||
|
||||
/**
|
||||
* Whether it should show the coverage or not.
|
||||
*/
|
||||
@ -37,6 +51,11 @@ final class Coverage implements AddsOutput, HandlesArguments
|
||||
*/
|
||||
public float $coverageMin = 0.0;
|
||||
|
||||
/**
|
||||
* Whether it should show only errors or not.
|
||||
*/
|
||||
public bool $errorsOnly = false;
|
||||
|
||||
/**
|
||||
* Creates a new Plugin instance.
|
||||
*/
|
||||
@ -51,7 +70,7 @@ final class Coverage implements AddsOutput, HandlesArguments
|
||||
public function handleArguments(array $originals): array
|
||||
{
|
||||
$arguments = [...[''], ...array_values(array_filter($originals, function (string $original): bool {
|
||||
foreach ([self::COVERAGE_OPTION, self::MIN_OPTION] as $option) {
|
||||
foreach (self::ALLOWED_OPTIONS as $option) {
|
||||
if ($original === sprintf('--%s', $option)) {
|
||||
return true;
|
||||
}
|
||||
@ -73,6 +92,7 @@ final class Coverage implements AddsOutput, HandlesArguments
|
||||
$inputs = [];
|
||||
$inputs[] = new InputOption(self::COVERAGE_OPTION, null, InputOption::VALUE_NONE);
|
||||
$inputs[] = new InputOption(self::MIN_OPTION, null, InputOption::VALUE_REQUIRED);
|
||||
$inputs[] = new InputOption(self::ERRORS_ONLY_OPTION, null, InputOption::VALUE_NONE);
|
||||
|
||||
$input = new ArgvInput($arguments, new InputDefinition($inputs));
|
||||
if ((bool) $input->getOption(self::COVERAGE_OPTION)) {
|
||||
@ -106,6 +126,10 @@ final class Coverage implements AddsOutput, HandlesArguments
|
||||
$this->coverageMin = (float) $minOption;
|
||||
}
|
||||
|
||||
if ((bool) $input->getOption(self::ERRORS_ONLY_OPTION)) {
|
||||
$this->errorsOnly = true;
|
||||
}
|
||||
|
||||
return $originals;
|
||||
}
|
||||
|
||||
@ -122,7 +146,7 @@ final class Coverage implements AddsOutput, HandlesArguments
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$coverage = \Pest\Support\Coverage::report($this->output);
|
||||
$coverage = \Pest\Support\Coverage::report($this->output, $this->coverageMin, $this->errorsOnly);
|
||||
|
||||
$exitCode = (int) ($coverage < $this->coverageMin);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user