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
+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()) {