Skip to content

Commit

Permalink
Make the --filter option shorter for PHPUnit (#1548)
Browse files Browse the repository at this point in the history
  • Loading branch information
maks-rafalko committed Sep 4, 2021
1 parent bba07d8 commit cb952c6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
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 \:\:"/',
];
}
}

0 comments on commit cb952c6

Please sign in to comment.