diff --git a/src/Plugins/Concerns/HandleArguments.php b/src/Plugins/Concerns/HandleArguments.php index 6fdcff8c..e12baec6 100644 --- a/src/Plugins/Concerns/HandleArguments.php +++ b/src/Plugins/Concerns/HandleArguments.php @@ -50,11 +50,14 @@ trait HandleArguments */ public function popArgument(string $argument, array $arguments): array { - $arguments = array_flip($arguments); + $key = array_search($argument, $arguments, true); - unset($arguments[$argument]); + while ($key !== false) { + unset($arguments[$key]); + $key = array_search($argument, $arguments, true); + } - return array_values(array_flip($arguments)); + return array_values($arguments); } /** diff --git a/src/Plugins/Coverage.php b/src/Plugins/Coverage.php index ed7b1214..50bbe8e3 100644 --- a/src/Plugins/Coverage.php +++ b/src/Plugins/Coverage.php @@ -17,6 +17,8 @@ use Symfony\Component\Console\Output\OutputInterface; */ final class Coverage implements AddsOutput, HandlesArguments { + use Concerns\HandleArguments; + private const string COVERAGE_OPTION = 'coverage'; private const string MIN_OPTION = 'min'; @@ -77,11 +79,9 @@ final class Coverage implements AddsOutput, HandlesArguments 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 e793ab48..e3e3a282 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -1716,6 +1716,8 @@ ✓ method hasArgument with ('someValue', true) ✓ method hasArgument with ('--a', false) ✓ method hasArgument with ('--undefined-argument', false) + ✓ popArgument preserves duplicate values when removing a missing argument + ✓ popArgument preserves duplicate values when removing an existing argument PASS Tests\Unit\Plugins\Environment ✓ environment is set to CI when --ci option is used @@ -1913,6 +1915,7 @@ ✓ parallel ✓ a parallel test can extend another test with same name ✓ parallel reports invalid datasets as failures + ✓ parallel can have multiple exclude-groups PASS Tests\Visual\ParallelNestedDatasets ✓ parallel loads nested datasets from nested directories @@ -1946,4 +1949,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, 35 skipped, 1335 passed (3024 assertions) \ No newline at end of file + Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 35 skipped, 1332 passed (3014 assertions) diff --git a/tests/Unit/Plugins/Concerns/HandleArguments.php b/tests/Unit/Plugins/Concerns/HandleArguments.php index 5cc91bb5..7f33c7c5 100644 --- a/tests/Unit/Plugins/Concerns/HandleArguments.php +++ b/tests/Unit/Plugins/Concerns/HandleArguments.php @@ -24,3 +24,27 @@ test('method hasArgument', function (string $argument, bool $expectedResult) { ['--a', false], ['--undefined-argument', false], ]); + +test('popArgument preserves duplicate values when removing a missing argument', function () { + $obj = new class + { + use HandleArguments; + }; + + $arguments = ['--verbose', '--exclude-group', 'firstGroup', '--exclude-group', 'secondGroup', '--filter=MyTest']; + $result = $obj->popArgument('--missingitem', $arguments); + + expect($result)->toBe($arguments); +}); + +test('popArgument preserves duplicate values when removing an existing argument', function () { + $obj = new class + { + use HandleArguments; + }; + + $arguments = ['--verbose', '--exclude-group', 'firstGroup', '--exclude-group', 'secondGroup', '--filter=MyTest']; + $result = $obj->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 6fc05865..f0eaff97 100644 --- a/tests/Visual/Parallel.php +++ b/tests/Visual/Parallel.php @@ -24,7 +24,7 @@ test('parallel', function () use ($run) { $file = file_get_contents(__FILE__); $file = preg_replace( '/\$expected = \'.*?\';/', - "\$expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 27 skipped, 1319 passed (2973 assertions)';", + "\$expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 27 skipped, 1315 passed (2961 assertions)';", $file, ); file_put_contents(__FILE__, $file); @@ -47,3 +47,14 @@ test('parallel reports invalid datasets as failures', function () use ($run) { ->toContain('Tests: 1 failed, 1 passed (1 assertions)') ->toContain('Parallel: 3 processes'); })->skipOnWindows(); + +test('parallel can have multiple exclude-groups', function () use ($run) { + $singleExclude = $run('--exclude-group=integration'); + $doubleExclude = $run('--exclude-group=integration', '--exclude-group=container'); + + preg_match('/(\d+) passed/', $singleExclude, $singleMatch); + preg_match('/(\d+) passed/', $doubleExclude, $doubleMatch); + + expect((int) $doubleMatch[1])->toBeLessThan((int) $singleMatch[1]); + expect($doubleExclude)->toContain('Parallel: 3 processes'); +})->skipOnWindows();