From 666fb4e7623b0adad593d01f292f69322fc609d4 Mon Sep 17 00:00:00 2001 From: flap152 Date: Sun, 24 Aug 2025 09:50:21 -0400 Subject: [PATCH 01/10] Commented-out debugging code Helped figure out what was happening, confirm the problem and workaround. Will be removed in later commit. --- src/Plugins/Actions/CallsHandleArguments.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/Plugins/Actions/CallsHandleArguments.php b/src/Plugins/Actions/CallsHandleArguments.php index 660620f99..fe6bb9d26 100644 --- a/src/Plugins/Actions/CallsHandleArguments.php +++ b/src/Plugins/Actions/CallsHandleArguments.php @@ -26,7 +26,24 @@ public static function execute(array $argv): array /** @var Plugins\HandlesArguments $plugin */ foreach ($plugins as $plugin) { + // $argvBackup = $argv; + // $before = array_filter($argv, fn($t) => $t === '--exclude-group' || $t === '--exclude-group=integration'|| $t === '--exclude-group=container'); + // if (count($before) !== 2) { + // echo "You need to specify --exclude-group=groupname"; + // echo $plugin::class; + // // var_dump($argv); + // exit('ASDFasdfasdfasfd'); + // } $argv = $plugin->handleArguments($argv); + // $after = array_filter($argv, fn($t) => $t === '--exclude-group' || $t === '--exclude-group=integration'|| $t === '--exclude-group=container'); + // if (count($before) !== count($after)) { + // echo sprintf("Plugin %s removed an argument illegally \r\n", $plugin::class) . PHP_EOL; + // echo $plugin::class; + // // var_dump($argv); + // // dd($argvBackup, $argv, $before, $after); + // // $argv = $argvBackup; + // } + } return $argv; From 7cfa7943aba2d076b95a798e8ef83b4c2f2baa64 Mon Sep 17 00:00:00 2001 From: flap152 Date: Sun, 24 Aug 2025 09:58:11 -0400 Subject: [PATCH 02/10] Add failing tests for `HandleArguments` trait and `Parallel`. Update existing Parallel test with correct expected counts --- .../Unit/Plugins/Concerns/HandleArguments.php | 21 +++++++++++++++++++ tests/Visual/Parallel.php | 10 ++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/tests/Unit/Plugins/Concerns/HandleArguments.php b/tests/Unit/Plugins/Concerns/HandleArguments.php index 5cc91bb53..bade690a4 100644 --- a/tests/Unit/Plugins/Concerns/HandleArguments.php +++ b/tests/Unit/Plugins/Concerns/HandleArguments.php @@ -2,6 +2,13 @@ use Pest\Plugins\Concerns\HandleArguments; + beforeEach(function () { + $this->handler = new class + { + use HandleArguments; + }; + }); + test('method hasArgument', function (string $argument, bool $expectedResult) { $obj = new class { @@ -24,3 +31,17 @@ ['--a', false], ['--undefined-argument', false], ]); + + test('popArgument keeps non-unique array item when called with missing argument', function () { + $arguments = ['--verbose', '--exclude-group', 'firstGroup', '--exclude-group', 'secondGroup', '--filter=MyTest']; + $result = $this->handler->popArgument('--missingitem', $arguments); + + expect($result)->toBe($arguments); + }); + + test('popArgument keeps non-unique array item when called with existing argument', function () { + $arguments = ['--verbose', '--exclude-group', 'firstGroup', '--exclude-group', 'secondGroup', '--filter=MyTest']; + $result = $this->handler->popArgument('--verbose', $arguments); + + expect($result)->toBe(['--exclude-group', 'firstGroup', '--exclude-group', 'secondGroup', '--filter=MyTest']); + }); \ No newline at end of file diff --git a/tests/Visual/Parallel.php b/tests/Visual/Parallel.php index f70c2826b..1b50bcbde 100644 --- a/tests/Visual/Parallel.php +++ b/tests/Visual/Parallel.php @@ -16,10 +16,18 @@ test('parallel', function () use ($run) { expect($run('--exclude-group=integration')) - ->toContain('Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 39 todos, 26 skipped, 1178 passed (2790 assertions)') + ->toContain('Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 39 todos, 26 skipped, 1180 passed (2792 assertions)') ->toContain('Parallel: 3 processes'); })->skipOnWindows(); + test('parallel can have multiple exclude-groups', function () use ($run) { + $args = ['--exclude-group=integration', '--exclude-group=container']; + + expect($run(...$args)) + ->toContain('Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 39 todos, 26 skipped, 1175 passed (2787 assertions)') + ->toContain('Parallel: 3 processes'); + })->skipOnWindows(); + test('a parallel test can extend another test with same name', function () use ($run) { expect($run('tests/Fixtures/Inheritance'))->toContain('Tests: 1 skipped, 2 passed (2 assertions)'); }); From faa318354d59a71dd4da90dec7640acc8b839eba Mon Sep 17 00:00:00 2001 From: flap152 Date: Sun, 24 Aug 2025 10:44:18 -0400 Subject: [PATCH 03/10] Fix popArgument() in `HandleArguments` trait and use popArgument() in Coverage plugin --- src/Plugins/Concerns/HandleArguments.php | 10 +++++++--- src/Plugins/Coverage.php | 6 +++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Plugins/Concerns/HandleArguments.php b/src/Plugins/Concerns/HandleArguments.php index 9cf5e606a..10f0e7efc 100644 --- a/src/Plugins/Concerns/HandleArguments.php +++ b/src/Plugins/Concerns/HandleArguments.php @@ -50,10 +50,14 @@ public function pushArgument(string $argument, array $arguments): array */ public function popArgument(string $argument, array $arguments): array { - $arguments = array_flip($arguments); + $args = $arguments; + $key = array_search($argument, $arguments, true); - unset($arguments[$argument]); + if ($key !== false) { + array_splice($args, $key, 1); + } + + return $args; - return array_values(array_flip($arguments)); } } diff --git a/src/Plugins/Coverage.php b/src/Plugins/Coverage.php index 712f5de55..5e2999611 100644 --- a/src/Plugins/Coverage.php +++ b/src/Plugins/Coverage.php @@ -17,6 +17,8 @@ */ final class Coverage implements AddsOutput, HandlesArguments { + use Concerns\HandleArguments; + private const string COVERAGE_OPTION = 'coverage'; private const string MIN_OPTION = 'min'; @@ -70,11 +72,9 @@ public function handleArguments(array $originals): array return false; }))]; - $originals = array_flip($originals); foreach ($arguments as $argument) { - unset($originals[$argument]); + $originals = $this->popArgument($argument, $originals); } - $originals = array_flip($originals); $inputs = []; $inputs[] = new InputOption(self::COVERAGE_OPTION, null, InputOption::VALUE_NONE); From 578ed2f4d70235c8d9b60c9b899917f7138813c1 Mon Sep 17 00:00:00 2001 From: flap152 Date: Sun, 24 Aug 2025 10:46:13 -0400 Subject: [PATCH 04/10] Remove commented-out debugging code --- src/Plugins/Actions/CallsHandleArguments.php | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/src/Plugins/Actions/CallsHandleArguments.php b/src/Plugins/Actions/CallsHandleArguments.php index fe6bb9d26..660620f99 100644 --- a/src/Plugins/Actions/CallsHandleArguments.php +++ b/src/Plugins/Actions/CallsHandleArguments.php @@ -26,24 +26,7 @@ public static function execute(array $argv): array /** @var Plugins\HandlesArguments $plugin */ foreach ($plugins as $plugin) { - // $argvBackup = $argv; - // $before = array_filter($argv, fn($t) => $t === '--exclude-group' || $t === '--exclude-group=integration'|| $t === '--exclude-group=container'); - // if (count($before) !== 2) { - // echo "You need to specify --exclude-group=groupname"; - // echo $plugin::class; - // // var_dump($argv); - // exit('ASDFasdfasdfasfd'); - // } $argv = $plugin->handleArguments($argv); - // $after = array_filter($argv, fn($t) => $t === '--exclude-group' || $t === '--exclude-group=integration'|| $t === '--exclude-group=container'); - // if (count($before) !== count($after)) { - // echo sprintf("Plugin %s removed an argument illegally \r\n", $plugin::class) . PHP_EOL; - // echo $plugin::class; - // // var_dump($argv); - // // dd($argvBackup, $argv, $before, $after); - // // $argv = $argvBackup; - // } - } return $argv; From 1964fd805c8472dc07a3c882ee0084eafb22eff7 Mon Sep 17 00:00:00 2001 From: flap152 Date: Tue, 26 Aug 2025 21:42:41 -0400 Subject: [PATCH 05/10] fixed indentation --- tests/Unit/Plugins/Concerns/HandleArguments.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/Unit/Plugins/Concerns/HandleArguments.php b/tests/Unit/Plugins/Concerns/HandleArguments.php index bade690a4..cca3f7d64 100644 --- a/tests/Unit/Plugins/Concerns/HandleArguments.php +++ b/tests/Unit/Plugins/Concerns/HandleArguments.php @@ -2,12 +2,12 @@ use Pest\Plugins\Concerns\HandleArguments; - beforeEach(function () { +beforeEach(function () { $this->handler = new class { use HandleArguments; }; - }); +}); test('method hasArgument', function (string $argument, bool $expectedResult) { $obj = new class @@ -32,16 +32,16 @@ ['--undefined-argument', false], ]); - test('popArgument keeps non-unique array item when called with missing argument', function () { +test('popArgument keeps non-unique array item when called with missing argument', function () { $arguments = ['--verbose', '--exclude-group', 'firstGroup', '--exclude-group', 'secondGroup', '--filter=MyTest']; $result = $this->handler->popArgument('--missingitem', $arguments); expect($result)->toBe($arguments); - }); +}); - test('popArgument keeps non-unique array item when called with existing argument', function () { +test('popArgument keeps non-unique array item when called with existing argument', function () { $arguments = ['--verbose', '--exclude-group', 'firstGroup', '--exclude-group', 'secondGroup', '--filter=MyTest']; $result = $this->handler->popArgument('--verbose', $arguments); expect($result)->toBe(['--exclude-group', 'firstGroup', '--exclude-group', 'secondGroup', '--filter=MyTest']); - }); \ No newline at end of file +}); From b2b06e3e81284640990e99c804be4793c99a5e92 Mon Sep 17 00:00:00 2001 From: flap152 Date: Tue, 26 Aug 2025 21:44:30 -0400 Subject: [PATCH 06/10] updated number of tests/assertions in test --- tests/Visual/Parallel.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Visual/Parallel.php b/tests/Visual/Parallel.php index 1b50bcbde..5c317f40a 100644 --- a/tests/Visual/Parallel.php +++ b/tests/Visual/Parallel.php @@ -20,13 +20,13 @@ ->toContain('Parallel: 3 processes'); })->skipOnWindows(); - test('parallel can have multiple exclude-groups', function () use ($run) { +test('parallel can have multiple exclude-groups', function () use ($run) { $args = ['--exclude-group=integration', '--exclude-group=container']; expect($run(...$args)) - ->toContain('Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 39 todos, 26 skipped, 1175 passed (2787 assertions)') + ->toContain('Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 39 todos, 26 skipped, 1173 passed (2785 assertions)') ->toContain('Parallel: 3 processes'); - })->skipOnWindows(); +})->skipOnWindows(); test('a parallel test can extend another test with same name', function () use ($run) { expect($run('tests/Fixtures/Inheritance'))->toContain('Tests: 1 skipped, 2 passed (2 assertions)'); From 130e554ad6b207fa536bec8c2e3130a49cf1aa4e Mon Sep 17 00:00:00 2001 From: flap152 Date: Tue, 26 Aug 2025 21:46:14 -0400 Subject: [PATCH 07/10] Fixed failing test when adding an empty string element ('') in the arguments array. --- tests/Visual/Todo.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Visual/Todo.php b/tests/Visual/Todo.php index 21b8963d1..24415c703 100644 --- a/tests/Visual/Todo.php +++ b/tests/Visual/Todo.php @@ -3,7 +3,7 @@ use Symfony\Component\Process\Process; $run = function (string $target, bool $parallel) { - $process = new Process(['php', 'bin/pest', $target, $parallel ? '--parallel' : ''], dirname(__DIR__, 2), + $process = new Process(['php', 'bin/pest', $target, ...($parallel ? ['--parallel'] : [])], dirname(__DIR__, 2), ['COLLISION_PRINTER' => 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true'], ); From 24e303f4272a01b62547a9421c20d70a9d8e56df Mon Sep 17 00:00:00 2001 From: flap152 Date: Tue, 26 Aug 2025 21:46:33 -0400 Subject: [PATCH 08/10] update success snapshot --- tests/.snapshots/success.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index bfa91bb1b..c133234b2 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -1608,6 +1608,8 @@ ✓ method hasArgument with ('someValue', true) ✓ method hasArgument with ('--a', false) ✓ method hasArgument with ('--undefined-argument', false) + ✓ popArgument keeps non-unique array item when called with missing argument + ✓ popArgument keeps non-unique array item when called with existing argument PASS Tests\Unit\Plugins\Environment ✓ environment is set to CI when --ci option is used @@ -1755,6 +1757,7 @@ PASS Tests\Visual\Parallel ✓ parallel + ✓ parallel can have multiple exclude-groups ✓ a parallel test can extend another test with same name PASS Tests\Visual\SingleTestOrDirectory @@ -1782,4 +1785,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, 39 todos, 35 skipped, 1188 passed (2814 assertions) \ No newline at end of file + Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 39 todos, 35 skipped, 1191 passed (2818 assertions) \ No newline at end of file From 2dace0e3575fa5765f9f79168a896922cec44be8 Mon Sep 17 00:00:00 2001 From: flap152 Date: Wed, 27 Aug 2025 14:45:13 -0400 Subject: [PATCH 09/10] Fix possible error when $arguments index was not sequential. Return re-indexed array to avoid problems for callers assuming the array is re-indexed. --- src/Plugins/Concerns/HandleArguments.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Plugins/Concerns/HandleArguments.php b/src/Plugins/Concerns/HandleArguments.php index 10f0e7efc..8b3b8cec5 100644 --- a/src/Plugins/Concerns/HandleArguments.php +++ b/src/Plugins/Concerns/HandleArguments.php @@ -43,21 +43,20 @@ public function pushArgument(string $argument, array $arguments): array } /** - * Pops the given argument from the arguments. + * Pops the given argument from the arguments and returns a re-indexed array. * * @param array $arguments * @return array */ public function popArgument(string $argument, array $arguments): array { - $args = $arguments; $key = array_search($argument, $arguments, true); if ($key !== false) { - array_splice($args, $key, 1); + unset($arguments[$key]); } - return $args; + return array_values($arguments); } } From 9c232afd2bd2c52a7dbf8661134ac15c56911722 Mon Sep 17 00:00:00 2001 From: flap152 Date: Mon, 22 Dec 2025 10:05:35 -0500 Subject: [PATCH 10/10] fix whitespace after manual merge conflict resolution --- tests/Visual/Parallel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Visual/Parallel.php b/tests/Visual/Parallel.php index 264d304be..3dac77a58 100644 --- a/tests/Visual/Parallel.php +++ b/tests/Visual/Parallel.php @@ -17,7 +17,7 @@ test('parallel', function () use ($run) { expect($run('--exclude-group=integration')) ->toContain('Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 39 todos, 26 skipped, 1179 passed (2792 assertions)') - ->toContain('Parallel: 3 processes'); + ->toContain('Parallel: 3 processes'); })->skipOnWindows(); test('parallel can have multiple exclude-groups', function () use ($run) {