mirror of
https://github.com/pestphp/pest.git
synced 2026-06-15 07:28:23 +02:00
fix: popArgument drops duplicate arguments breaking --parallel --exclude-gropup= (#1674)
* fix: popArgument drops duplicate arguments breaking --parallel multi-exclude-group Fixes #1437 * fix: ensure popArgument handles duplicate arguments * fix: update expected test results and snapshots after rebase --------- Signed-off-by: nuno maduro <enunomaduro@gmail.com> Co-authored-by: nuno maduro <enunomaduro@gmail.com>
This commit is contained in:
@ -50,11 +50,14 @@ trait HandleArguments
|
|||||||
*/
|
*/
|
||||||
public function popArgument(string $argument, array $arguments): array
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -17,6 +17,8 @@ use Symfony\Component\Console\Output\OutputInterface;
|
|||||||
*/
|
*/
|
||||||
final class Coverage implements AddsOutput, HandlesArguments
|
final class Coverage implements AddsOutput, HandlesArguments
|
||||||
{
|
{
|
||||||
|
use Concerns\HandleArguments;
|
||||||
|
|
||||||
private const string COVERAGE_OPTION = 'coverage';
|
private const string COVERAGE_OPTION = 'coverage';
|
||||||
|
|
||||||
private const string MIN_OPTION = 'min';
|
private const string MIN_OPTION = 'min';
|
||||||
@ -77,11 +79,9 @@ final class Coverage implements AddsOutput, HandlesArguments
|
|||||||
return false;
|
return false;
|
||||||
}))];
|
}))];
|
||||||
|
|
||||||
$originals = array_flip($originals);
|
|
||||||
foreach ($arguments as $argument) {
|
foreach ($arguments as $argument) {
|
||||||
unset($originals[$argument]);
|
$originals = $this->popArgument($argument, $originals);
|
||||||
}
|
}
|
||||||
$originals = array_flip($originals);
|
|
||||||
|
|
||||||
$inputs = [];
|
$inputs = [];
|
||||||
$inputs[] = new InputOption(self::COVERAGE_OPTION, null, InputOption::VALUE_NONE);
|
$inputs[] = new InputOption(self::COVERAGE_OPTION, null, InputOption::VALUE_NONE);
|
||||||
|
|||||||
@ -1716,6 +1716,8 @@
|
|||||||
✓ method hasArgument with ('someValue', true)
|
✓ method hasArgument with ('someValue', true)
|
||||||
✓ method hasArgument with ('--a', false)
|
✓ method hasArgument with ('--a', false)
|
||||||
✓ method hasArgument with ('--undefined-argument', 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
|
PASS Tests\Unit\Plugins\Environment
|
||||||
✓ environment is set to CI when --ci option is used
|
✓ environment is set to CI when --ci option is used
|
||||||
@ -1913,6 +1915,7 @@
|
|||||||
✓ parallel
|
✓ parallel
|
||||||
✓ a parallel test can extend another test with same name
|
✓ a parallel test can extend another test with same name
|
||||||
✓ parallel reports invalid datasets as failures
|
✓ parallel reports invalid datasets as failures
|
||||||
|
✓ parallel can have multiple exclude-groups
|
||||||
|
|
||||||
PASS Tests\Visual\ParallelNestedDatasets
|
PASS Tests\Visual\ParallelNestedDatasets
|
||||||
✓ parallel loads nested datasets from nested directories
|
✓ parallel loads nested datasets from nested directories
|
||||||
@ -1946,4 +1949,4 @@
|
|||||||
✓ pass with dataset with ('my-datas-set-value')
|
✓ pass with dataset with ('my-datas-set-value')
|
||||||
✓ within describe → 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)
|
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 35 skipped, 1332 passed (3014 assertions)
|
||||||
|
|||||||
@ -24,3 +24,27 @@ test('method hasArgument', function (string $argument, bool $expectedResult) {
|
|||||||
['--a', false],
|
['--a', false],
|
||||||
['--undefined-argument', 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']);
|
||||||
|
});
|
||||||
|
|||||||
@ -24,7 +24,7 @@ test('parallel', function () use ($run) {
|
|||||||
$file = file_get_contents(__FILE__);
|
$file = file_get_contents(__FILE__);
|
||||||
$file = preg_replace(
|
$file = preg_replace(
|
||||||
'/\$expected = \'.*?\';/',
|
'/\$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,
|
||||||
);
|
);
|
||||||
file_put_contents(__FILE__, $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('Tests: 1 failed, 1 passed (1 assertions)')
|
||||||
->toContain('Parallel: 3 processes');
|
->toContain('Parallel: 3 processes');
|
||||||
})->skipOnWindows();
|
})->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();
|
||||||
|
|||||||
Reference in New Issue
Block a user