From 53de32e963a2008a7f7e6500718bb59ffacf5899 Mon Sep 17 00:00:00 2001 From: maks-rafalko Date: Sun, 8 Aug 2021 00:55:42 +0300 Subject: [PATCH] Make the `--filter` option shorter for PHPUnit --- .../ArgumentsAndOptionsBuilder.php | 9 +++++ .../ArgumentsAndOptionsBuilderTest.php | 37 ++++++++++++++++--- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/src/TestFramework/PhpUnit/CommandLine/ArgumentsAndOptionsBuilder.php b/src/TestFramework/PhpUnit/CommandLine/ArgumentsAndOptionsBuilder.php index cfadbb9cc..e0ea9434f 100644 --- a/src/TestFramework/PhpUnit/CommandLine/ArgumentsAndOptionsBuilder.php +++ b/src/TestFramework/PhpUnit/CommandLine/ArgumentsAndOptionsBuilder.php @@ -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 @@ -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; } diff --git a/tests/phpunit/TestFramework/PhpUnit/CommandLine/ArgumentsAndOptionsBuilderTest.php b/tests/phpunit/TestFramework/PhpUnit/CommandLine/ArgumentsAndOptionsBuilderTest.php index 5a271b666..fd56910d9 100644 --- a/tests/phpunit/TestFramework/PhpUnit/CommandLine/ArgumentsAndOptionsBuilderTest.php +++ b/tests/phpunit/TestFramework/PhpUnit/CommandLine/ArgumentsAndOptionsBuilderTest.php @@ -142,7 +142,7 @@ public function provideTestCases(): Generator [ 'App\Test::test_case1', ], - '/App\\\\Test\:\:test_case1/', + '/Test\:\:test_case1/', ]; yield '2 test cases' => [ @@ -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 \:\:"/', ]; } }