Files
pest/tests/Plugins/Coverage.php
T
Youssef Mansour 557aca75a0 fix: accept space separated values for --min and --exactly (#1921)
`--min` and `--exactly` only accepted the `--min=50` notation. When the
space separated notation was used, the plugin kept the `--min` token but
left the `50` token behind, so `ArgvInput` received an option without a
value and threw:

    $ pest --coverage --min 50

    Symfony\Component\Console\Exception\RuntimeException
    The "--min" option requires a value.

The run aborted with an unhandled exception and a stack trace, even
though every other valued option Pest forwards to PHPUnit accepts both
notations (`pest --filter add` works). The orphaned value token was also
forwarded to PHPUnit as a positional argument.

`handleArguments()` now walks the arguments positionally instead of
filtering them, so an option that takes a value also claims the token
that follows it. Value-less options (`--coverage`, `--only-covered`) keep
their current behaviour and never consume the next token, and a bare
`--min` with no value still produces the regular "requires a value"
error rather than swallowing the option that follows it.
2026-12-03 14:00:33 +00:00

57 lines
1.9 KiB
PHP

<?php
use Pest\Plugins\Coverage;
use Symfony\Component\Console\Output\NullOutput;
test('compute comparable coverage', function (float $givenValue, float $expectedValue): void {
$output = new NullOutput;
$plugin = new Coverage($output);
$comparableCoverage = (fn () => $this->computeComparableCoverage($givenValue))->call($plugin);
expect($comparableCoverage)->toBe($expectedValue);
})->with([
[0, 0],
[0.5, 0.5],
[1.0, 1.0],
[32.51, 32.5],
[32.12312321312312, 32.1],
[32.53333333333333, 32.5],
[32.57777771232132, 32.5],
[100.0, 100.0],
]);
test('coverage options accept a space separated value', function (array $arguments, float $min, ?float $exactly): void {
$plugin = new Coverage(new NullOutput);
$plugin->handleArguments($arguments);
expect($plugin->coverageMin)->toBe($min)
->and($plugin->coverageExactly)->toBe($exactly);
})->with([
'min with equals sign' => [['--min=50'], 50.0, null],
'min with space' => [['--min', '50'], 50.0, null],
'exactly with equals sign' => [['--exactly=100'], 0.0, 100.0],
'exactly with space' => [['--exactly', '100'], 0.0, 100.0],
'both with space' => [['--min', '50', '--exactly', '100'], 50.0, 100.0],
]);
test('coverage options do not consume arguments owned by phpunit', function (): void {
$plugin = new Coverage(new NullOutput);
$arguments = $plugin->handleArguments(['--min', '50', '--filter', 'add', 'tests/Unit']);
expect($plugin->coverageMin)->toBe(50.0)
->and($arguments)->toBe(['--filter', 'add', 'tests/Unit']);
});
test('value less coverage options do not consume the next argument', function (): void {
$plugin = new Coverage(new NullOutput);
$arguments = $plugin->handleArguments(['--only-covered', '--filter', 'add']);
expect($plugin->showOnlyCovered)->toBeTrue()
->and($arguments)->toBe(['--filter', 'add']);
});