diff --git a/src/Plugins/Concerns/HandleArguments.php b/src/Plugins/Concerns/HandleArguments.php index 9cf5e606a..8b3b8cec5 100644 --- a/src/Plugins/Concerns/HandleArguments.php +++ b/src/Plugins/Concerns/HandleArguments.php @@ -43,17 +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 { - $arguments = array_flip($arguments); + $key = array_search($argument, $arguments, true); - unset($arguments[$argument]); + if ($key !== false) { + unset($arguments[$key]); + } + + return array_values($arguments); - 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); 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 diff --git a/tests/Unit/Plugins/Concerns/HandleArguments.php b/tests/Unit/Plugins/Concerns/HandleArguments.php index 5cc91bb53..cca3f7d64 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']); +}); diff --git a/tests/Visual/Parallel.php b/tests/Visual/Parallel.php index 93d2059d5..3dac77a58 100644 --- a/tests/Visual/Parallel.php +++ b/tests/Visual/Parallel.php @@ -16,7 +16,15 @@ test('parallel', function () use ($run) { expect($run('--exclude-group=integration')) - ->toContain('Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 39 todos, 26 skipped, 1177 passed (2790 assertions)') + ->toContain('Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 39 todos, 26 skipped, 1179 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, 1173 passed (2785 assertions)') ->toContain('Parallel: 3 processes'); })->skipOnWindows(); 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'], );