Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the --filter option shorter for PHPUnit #1548

Merged
merged 1 commit into from Sep 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -39,12 +39,14 @@
use function array_map;
use function array_merge;
use function count;
use function end;
use function explode;
use Infection\AbstractTestFramework\Coverage\TestLocation;
use Infection\TestFramework\CommandLineArgumentsAndOptionsBuilder;
use function ltrim;
use function preg_quote;
use function rtrim;
use function Safe\sprintf;

/**
* @internal
Expand Down Expand Up @@ -91,6 +93,13 @@ public function buildForMutant(string $configPath, string $extraOptions, array $
foreach ($tests as $testLocation) {
$testCaseString = $testLocation->getMethod();

$partsDelimitedByColons = explode('::', $testCaseString, 2);

if (count($partsDelimitedByColons) > 1) {
$parts = explode('\\', $partsDelimitedByColons[0]);
$testCaseString = sprintf('%s::%s', end($parts), $partsDelimitedByColons[1]);
}

if (array_key_exists($testCaseString, $usedTestCases)) {
continue;
}
Expand Down
Expand Up @@ -142,7 +142,7 @@ public function provideTestCases(): Generator
[
'App\Test::test_case1',
],
'/App\\\\Test\:\:test_case1/',
'/Test\:\:test_case1/',
];

yield '2 test cases' => [
Expand All @@ -151,25 +151,50 @@ public function provideTestCases(): Generator
'App\Test::test_case1',
'App\Test::test_case2',
],
'/App\\\\Test\:\:test_case1|App\\\\Test\:\:test_case2/',
'/Test\:\:test_case1|Test\:\:test_case2/',
];

yield '2 simple test cases, 1 with data set and special character >' => [
yield '1 simple test case, 1 with data set and special character >' => [
true,
[
'App\Test::test_case1 with data set "With special character >"',
'App\Test::test_case2',
],
'/App\\\\Test\:\:test_case1 with data set "With special character \\>"|App\\\\Test\:\:test_case2/',
'/Test\:\:test_case1 with data set "With special character \\>"|Test\:\:test_case2/',
];

yield '2 simple test cases, 1 with data set and special character @' => [
yield '1 simple test case, 1 with data set and special character @' => [
true,
[
'App\Test::test_case1 with data set "With special character @"',
'App\Test::test_case2',
],
'/App\\\\Test\:\:test_case1 with data set "With special character @"|App\\\\Test\:\:test_case2/',
'/Test\:\:test_case1 with data set "With special character @"|Test\:\:test_case2/',
];

yield '2 data sets from data provider for the same test case' => [
true,
[
'App\Test::test_case1 with data set "#1"',
'App\Test::test_case1 with data set "#2"',
],
'/Test\:\:test_case1 with data set "\#1"|Test\:\:test_case1 with data set "\#2"/',
];

yield '1 data set from data provider "With special char \\"' => [
true,
[
'App\Test::test_case1 with data set "With special char \\"',
],
'/Test\:\:test_case1 with data set "With special char \\\\"/',
];

yield '1 data set from data provider "With special chars ::"' => [
true,
[
'App\Test::test_case1 with data set "With special chars ::"',
],
'/Test\:\:test_case1 with data set "With special chars \:\:"/',
];
}
}