fix: keep the options that Pest adds before -- (#2087)

* fix: keep added options before the `--` separator

Pest added its own options (`--runner`, `--cache-directory`, `--teamcity`, `--no-coverage`, ...) after the `--` that the user gave. PHPUnit and ParaTest then read them as paths, thus `pest -- <path>` and `pest --parallel -- <path>` failed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: keep every option that Pest adds before `--`

pushArgument renumbers the list before it searches `--`, because bin/pest unsets options without array_values. Coverage, Shard and the `--teamcity` handling of bin/pest now place their options before `--` too. The changed files lose their comments, as AGENTS.md section 4 asks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Punyapal Shah <mrpunyapal@gmail.com>
This commit is contained in:
Jhon Farias
2026-12-04 10:11:42 +01:00
committed by GitHub
parent 59c1cb78f8
commit d2c1b99236
11 changed files with 73 additions and 34 deletions
+1 -6
View File
@@ -20,7 +20,6 @@ use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Output\ConsoleOutput;
(static function () {
// Ensures Collision's Printer is registered.
$_SERVER['COLLISION_PRINTER'] = 'DefaultPrinter';
$arguments = $originalArguments = $_SERVER['argv'];
@@ -123,8 +122,7 @@ use Symfony\Component\Console\Output\ConsoleOutput;
}
if ($value === '--teamcity') {
unset($arguments[$key]);
$arguments[] = '--no-output';
$arguments[$key] = '--no-output';
unset($_SERVER['COLLISION_PRINTER']);
}
}
@@ -143,7 +141,6 @@ use Symfony\Component\Console\Output\ConsoleOutput;
$isOptionValue = false;
// Convert namespace-style arguments (e.g. Tests\Unit\TestName) to file paths.
foreach ($arguments as $key => $value) {
if ($isOptionValue) {
$isOptionValue = false;
@@ -173,7 +170,6 @@ use Symfony\Component\Console\Output\ConsoleOutput;
continue;
}
// Try lowercasing the first directory segment (e.g. Tests -> tests).
$segments = explode(DIRECTORY_SEPARATOR, $path);
$segments[0] = lcfirst($segments[0]);
$lowercasedPath = implode(DIRECTORY_SEPARATOR, $segments);
@@ -183,7 +179,6 @@ use Symfony\Component\Console\Output\ConsoleOutput;
}
}
// Used when Pest is required using composer.
$autoloadPath = $GLOBALS['_composer_autoload_path'] ?? dirname(__DIR__, 3).'/autoload.php';
if (! is_file($autoloadPath)) {
+10 -1
View File
@@ -33,7 +33,16 @@ trait HandleArguments
*/
public function pushArgument(string $argument, array $arguments): array
{
$arguments[] = $argument;
$arguments = array_values($arguments);
$endOfOptionsPosition = array_search('--', $arguments, true);
if ($endOfOptionsPosition === false) {
$arguments[] = $argument;
return $arguments;
}
array_splice($arguments, $endOfOptionsPosition, 0, [$argument]);
return $arguments;
}
+3 -12
View File
@@ -47,14 +47,8 @@ final class Coverage implements AddsOutput, HandlesArguments
public bool $showOnlyCovered = false;
public function __construct(private readonly OutputInterface $output)
{
//
}
public function __construct(private readonly OutputInterface $output) {}
/**
* {@inheritdoc}
*/
public function handleArguments(array $originals): array
{
[$arguments, $originals] = $this->extractOwnArguments($originals);
@@ -68,8 +62,8 @@ final class Coverage implements AddsOutput, HandlesArguments
$input = new ArgvInput($arguments, new InputDefinition($inputs));
if ((bool) $input->getOption(self::COVERAGE_OPTION)) {
$this->coverage = true;
$originals[] = '--coverage-php';
$originals[] = \Pest\Support\Coverage::getPath();
$originals = $this->pushArgument('--coverage-php', $originals);
$originals = $this->pushArgument(\Pest\Support\Coverage::getPath(), $originals);
if (! \Pest\Support\Coverage::isAvailable()) {
if (\Pest\Support\Coverage::usingXdebug()) {
@@ -158,9 +152,6 @@ final class Coverage implements AddsOutput, HandlesArguments
return [['', ...$owned], $forwarded];
}
/**
* {@inheritdoc}
*/
public function addOutput(int $exitCode): int
{
if (Parallel::isWorker()) {
+1 -4
View File
@@ -79,9 +79,6 @@ final class Parallel implements HandlesArguments
return null;
}
/**
* {@inheritdoc}
*/
public function handleArguments(array $arguments): array
{
if ($this->hasArgumentsThatWouldBeFasterWithoutParallel()) {
@@ -182,7 +179,7 @@ final class Parallel implements HandlesArguments
{
$argv = new ArgvInput;
if ($argv->hasParameterOption('--teamcity')) {
$arguments[] = '--teamcity';
$arguments = $this->pushArgument('--teamcity', $arguments);
}
return $arguments;
+4 -8
View File
@@ -98,9 +98,7 @@ final class Shard implements AddsOutput, HandlesArguments, Terminable
public function __construct(
private readonly OutputInterface $output,
) {
//
}
) {}
public static function useTimingsFile(string $filename): void
{
@@ -144,9 +142,6 @@ final class Shard implements AddsOutput, HandlesArguments, Terminable
return self::$ownership[$unit];
}
/**
* {@inheritDoc}
*/
public function handleArguments(array $arguments): array
{
if ($this->hasArgument('--update-shards', $arguments)) {
@@ -220,7 +215,8 @@ final class Shard implements AddsOutput, HandlesArguments, Terminable
$this->ensureFilterLengthIsSafe($filter);
$arguments = [...$arguments, '--filter', $filter];
$arguments = $this->pushArgument('--filter', $arguments);
$arguments = $this->pushArgument($filter, $arguments);
if ($this->hasArgument('--do-not-fail-on-empty-test-suite', $arguments) || $this->hasArgument('--fail-on-empty-test-suite', $arguments)) {
return $arguments;
@@ -350,7 +346,7 @@ final class Shard implements AddsOutput, HandlesArguments, Terminable
}
}
return [PHP_BINARY, ...$filtered, '--test-directory='.$testPath, '--list-tests'];
return [PHP_BINARY, ...$this->pushArgument('--list-tests', $this->pushArgument('--test-directory='.$testPath, $filtered))];
}
/**
+1 -1
View File
@@ -1734,7 +1734,7 @@ final class Tia implements AddsOutput, HandlesArguments, HandlesOriginalArgument
}
if (! $this->piggybackCoverage && ! in_array('--no-coverage', $arguments, true)) {
$arguments[] = '--no-coverage';
$arguments = $this->pushArgument('--no-coverage', $arguments);
}
if (Parallel::isEnabled()) {
+7 -1
View File
@@ -1893,6 +1893,9 @@
✓ popArgument preserves duplicate values when removing a missing argument
✓ popArgument preserves duplicate values when removing an existing argument
PASS Tests\Unit\Plugins\Concerns\PushArgument
✓ pushArgument inserts before the option separator when the keys have gaps
PASS Tests\Unit\Plugins\Environment
✓ environment is set to CI when --ci option is used
✓ environment is set to Local when --ci option is not used
@@ -2751,6 +2754,7 @@
✓ parallel does not record the test run history when asked not to with ('--do-not-record-test-run-history')
✓ parallel group-filtered run is not considered empty when a worker ends on a fully filtered file
✓ parallel group-filtered run still fails when the selection matches no tests
✓ parallel accepts a path after the option separator
PASS Tests\Visual\ParallelIncludePath
✓ parallel resolves requires through the include path with dataset "value in the same argument"
@@ -2861,6 +2865,7 @@
✓ an empty shard runs no tests with dataset "parallel with fail-on-empty-test-suite"
✓ an empty shard lists no tests
✓ a non-empty shard runs its assigned test
✓ shard accepts a path after the option separator
PASS Tests\Visual\SingleTestOrDirectory
✓ allows to run a single test
@@ -2869,6 +2874,7 @@
✓ keeps namespace filters unchanged
✓ converts a namespace after the retry flag
✓ it disable decorating printer when colors is set to never
✓ allows to run a single test after the option separator
WARN Tests\Visual\Success
- visual snapshot of test suite on success
@@ -2898,4 +2904,4 @@
✓ pass with dataset with ('my-datas-set-value')
✓ within describe → pass with dataset with ('my-datas-set-value')
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 45 skipped, 2151 passed (4730 assertions)
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 45 skipped, 2155 passed (4735 assertions)
@@ -0,0 +1,15 @@
<?php
use Pest\Plugins\Concerns\HandleArguments;
test('pushArgument inserts before the option separator when the keys have gaps', function (): void {
$argumentHandler = new class
{
use HandleArguments;
};
$arguments = [0 => 'bin/pest', 2 => '--', 3 => 'tests/Fixtures/ExampleTest.php'];
expect($argumentHandler->pushArgument('--no-output', $arguments))
->toBe(['bin/pest', '--no-output', '--', 'tests/Fixtures/ExampleTest.php']);
});
+7 -1
View File
@@ -21,7 +21,7 @@ test('parallel', function () use ($run): void {
$output = implode("\n", array_slice(explode("\n", (string) $output), -10));
$profileOutput = $run('tests/Fixtures/Suites/SuccessOnly.php', '--profile');
$expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 37 skipped, 2004 passed (4168 assertions)';
$expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 37 skipped, 2005 passed (4169 assertions)';
expect($output)
->toContain("Tests: {$expected}")
@@ -162,3 +162,9 @@ test('parallel group-filtered run still fails when the selection matches no test
expect(removeAnsiEscapeSequences($process->getOutput()))->toContain('No tests found.')
->and($process->getExitCode())->toBe(1);
})->skipOnWindows();
test('parallel accepts a path after the option separator', function () use ($run): void {
expect($run('--', 'tests/Fixtures/ExampleTest.php'))
->toContain('Tests: 1 passed (1 assertions)')
->toContain('Parallel: 3 processes');
})->skipOnWindows();
+12
View File
@@ -47,3 +47,15 @@ test('a non-empty shard runs its assigned test', function (): void {
expect($process->getExitCode())->toBe(0)
->and($process->getOutput())->toContain('1 passed', '1 of 2 — 1 file ran, out of 1.');
});
test('shard accepts a path after the option separator', function (): void {
$process = new Process(
['php', 'bin/pest', '--shard=1/2', '--', 'tests/Fixtures/ExampleTest.php'],
dirname(__DIR__, 2),
['COLLISION_PRINTER' => 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true', 'PAO_DISABLE' => '1'],
);
$process->run();
expect(removeAnsiEscapeSequences($process->getOutput()))->toContain('Tests: 1 passed (1 assertions)');
})->skipOnWindows();
+12
View File
@@ -79,3 +79,15 @@ it('disable decorating printer when colors is set to never', function () use ($s
$output = $process->getOutput();
expect($output)->toContain($snapshot('disable-decorating-printer'));
})->skipOnWindows();
test('allows to run a single test after the option separator', function (): void {
$process = new Process(
['php', 'bin/pest', '--', 'tests/Fixtures/ExampleTest.php'],
dirname(__DIR__, 2),
['COLLISION_PRINTER' => 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true', 'PAO_DISABLE' => '1'],
);
$process->run();
expect(removeAnsiEscapeSequences($process->getOutput()))->toContain('Tests: 1 passed (1 assertions)');
})->skipOnWindows();