Skip to content

Commit

Permalink
Add more tests, remove redundant .* from regular expression
Browse files Browse the repository at this point in the history
  • Loading branch information
maks-rafalko committed Jul 25, 2021
1 parent 87efcb2 commit 119ca3f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 9 deletions.
Expand Up @@ -45,6 +45,7 @@
use Infection\AbstractTestFramework\Coverage\TestLocation;
use Infection\TestFramework\CommandLineArgumentsAndOptionsBuilder;
use function ltrim;
use function Safe\sprintf;

/**
* @internal
Expand Down Expand Up @@ -74,16 +75,14 @@ public function buildForMutant(string $configPath, string $extraOptions, array $
{
$options = $this->buildForInitialTestsRun($configPath, $extraOptions);

// preg_replace('/\swith data set (.*)/', '', $test->getMethod())

if (count($tests) > 0) {
$escapedTests = array_map(
static fn (TestLocation $testLocation): string => escapeshellcmd($testLocation->getMethod()),
$tests
);

$options[] = '--filter';
$options[] = implode('|', array_unique($escapedTests));
$options[] = sprintf('/%s/', implode('|', array_unique($escapedTests)));
}

return $options;
Expand Down
Expand Up @@ -35,6 +35,8 @@

namespace Infection\Tests\TestFramework\PhpUnit\CommandLine;

use function array_map;
use Generator;
use Infection\AbstractTestFramework\Coverage\TestLocation;
use Infection\TestFramework\PhpUnit\CommandLine\ArgumentsAndOptionsBuilder;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -93,7 +95,10 @@ public function test_it_can_build_the_command_with_extra_options_that_contains_s
);
}

public function test_it_can_build_the_command_with_filter_option_for_covering_tests_for_mutant(): void
/**
* @dataProvider provideTestCases
*/
public function test_it_can_build_the_command_with_filter_option_for_covering_tests_for_mutant(array $testCases, string $expectedFilterOptionValue): void
{
$configPath = '/the config/path';

Expand All @@ -103,16 +108,50 @@ public function test_it_can_build_the_command_with_filter_option_for_covering_te
$configPath,
'--path=/a path/with spaces',
'--filter',
'App\\\\Test::test_case1|App\\\\Test::test_case2',
$expectedFilterOptionValue,
],
$this->builder->buildForMutant(
$configPath,
'--path=/a path/with spaces',
[
TestLocation::forTestMethod('App\Test::test_case1'),
TestLocation::forTestMethod('App\Test::test_case2'),
]
array_map(
static fn (string $testCase): TestLocation => TestLocation::forTestMethod($testCase),
$testCases
)
)
);
}

public function provideTestCases(): Generator
{
yield '1 test case' => [
[
'App\Test::test_case1',
],
'/App\\\\Test::test_case1/',
];

yield '2 test cases' => [
[
'App\Test::test_case1',
'App\Test::test_case2',
],
'/App\\\\Test::test_case1|App\\\\Test::test_case2/',
];

yield '2 simple test cases, 1 with data set and special character >' => [
[
'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/',
];

yield '2 simple test cases, 1 with data set and special character @' => [
[
'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/',
];
}
}

0 comments on commit 119ca3f

Please sign in to comment.