Skip to content

Commit

Permalink
Split ArgumentsAndOptionsBuilder::build into 2 methods: for initial…
Browse files Browse the repository at this point in the history
… tests run and for mutant
  • Loading branch information
maks-rafalko committed Jul 25, 2021
1 parent e9b7549 commit 87efcb2
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 28 deletions.
33 changes: 17 additions & 16 deletions src/TestFramework/AbstractTestFrameworkAdapter.php
Expand Up @@ -91,7 +91,10 @@ public function getInitialTestRunCommandLine(
array $phpExtraArgs,
bool $skipCoverage
): array {
return $this->getCommandLine($this->buildInitialConfigFile(), $extraOptions, $phpExtraArgs, []);
return $this->getCommandLine(
$phpExtraArgs,
$this->argumentsAndOptionsBuilder->buildForInitialTestsRun($this->buildInitialConfigFile(), $extraOptions)
);
}

/**
Expand All @@ -109,15 +112,17 @@ public function getMutantCommandLine(
string $extraOptions
): array {
return $this->getCommandLine(
$this->buildMutationConfigFile(
$tests,
$mutantFilePath,
$mutationHash,
$mutationOriginalFilePath
),
$extraOptions,
[],
$tests,
$this->argumentsAndOptionsBuilder->buildForMutant(
$this->buildMutationConfigFile(
$tests,
$mutantFilePath,
$mutationHash,
$mutationOriginalFilePath
),
$extraOptions,
$tests
)
);
}

Expand Down Expand Up @@ -155,22 +160,18 @@ protected function buildMutationConfigFile(

/**
* @param string[] $phpExtraArgs
* @param TestLocation[] $tests
* @param string[] $testFrameworkArgs
*
* @return string[]
*/
private function getCommandLine(
string $configPath,
string $extraOptions,
array $phpExtraArgs,
array $tests
array $testFrameworkArgs
): array {
$frameworkArgs = $this->argumentsAndOptionsBuilder->build($configPath, $extraOptions, $tests);

return $this->commandLineBuilder->build(
$this->testFrameworkExecutable,
$phpExtraArgs,
$frameworkArgs
$testFrameworkArgs
);
}

Expand Down
7 changes: 6 additions & 1 deletion src/TestFramework/CommandLineArgumentsAndOptionsBuilder.php
Expand Up @@ -42,10 +42,15 @@
*/
interface CommandLineArgumentsAndOptionsBuilder
{
/**
* @return string[]
*/
public function buildForInitialTestsRun(string $configPath, string $extraOptions): array;

/**
* @param TestLocation[] $tests
*
* @return string[]
*/
public function build(string $configPath, string $extraOptions, array $tests): array;
public function buildForMutant(string $configPath, string $extraOptions, array $tests): array;
}
Expand Up @@ -51,8 +51,7 @@
*/
final class ArgumentsAndOptionsBuilder implements CommandLineArgumentsAndOptionsBuilder
{
// todo build & buildForMutant
public function build(string $configPath, string $extraOptions, array $tests): array
public function buildForInitialTestsRun(string $configPath, string $extraOptions): array
{
$options = [
'--configuration',
Expand All @@ -68,6 +67,13 @@ public function build(string $configPath, string $extraOptions, array $tests): a
);
}

return $options;
}

public function buildForMutant(string $configPath, string $extraOptions, array $tests): array
{
$options = $this->buildForInitialTestsRun($configPath, $extraOptions);

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

if (count($tests) > 0) {
Expand Down
Expand Up @@ -129,7 +129,7 @@ public function test_it_provides_initial_test_run_command_line_when_no_coverage_
{
$this->cliArgumentsBuilder
->expects($this->once())
->method('build')
->method('buildForInitialTestsRun')
->with('', '--group=default')
;

Expand Down Expand Up @@ -163,7 +163,7 @@ public function test_it_provides_initial_test_run_command_line_when_coverage_rep
{
$this->cliArgumentsBuilder
->expects($this->once())
->method('build')
->method('buildForInitialTestsRun')
->with('', '--group=default --coverage-xml=/tmp/coverage-xml --log-junit=/tmp/infection/junit.xml')
->willReturn([
'--group=default', '--coverage-xml=/tmp/coverage-xml', '--log-junit=/tmp/infection/junit.xml',
Expand Down Expand Up @@ -215,7 +215,7 @@ public function test_it_provides_initial_test_run_command_line_when_coverage_rep
{
$this->cliArgumentsBuilder
->expects($this->once())
->method('build')
->method('buildForInitialTestsRun')
->with('', '--group=default --coverage-xml=/tmp/coverage-xml --log-junit=/tmp/infection/junit.xml')
->willReturn([
'--group=default', '--coverage-xml=/tmp/coverage-xml', '--log-junit=/tmp/infection/junit.xml',
Expand Down
Expand Up @@ -129,7 +129,7 @@ public function test_it_provides_initial_test_run_command_line_when_no_coverage_
{
$this->cliArgumentsBuilder
->expects($this->once())
->method('build')
->method('buildForInitialTestsRun')
->with('', '--group=default')
;

Expand Down Expand Up @@ -163,7 +163,7 @@ public function test_it_provides_initial_test_run_command_line_when_coverage_rep
{
$this->cliArgumentsBuilder
->expects($this->once())
->method('build')
->method('buildForInitialTestsRun')
->with('', '--group=default --coverage-xml=/tmp/coverage-xml --log-junit=/tmp/infection/junit.xml')
->willReturn([
'--group=default', '--coverage-xml=/tmp/coverage-xml', '--log-junit=/tmp/infection/junit.xml',
Expand Down Expand Up @@ -215,7 +215,7 @@ public function test_it_provides_initial_test_run_command_line_when_coverage_rep
{
$this->cliArgumentsBuilder
->expects($this->once())
->method('build')
->method('buildForInitialTestsRun')
->with('', '--group=default --coverage-xml=/tmp/coverage-xml --log-junit=/tmp/infection/junit.xml')
->willReturn([
'--group=default', '--coverage-xml=/tmp/coverage-xml', '--log-junit=/tmp/infection/junit.xml',
Expand Down
Expand Up @@ -60,7 +60,7 @@ public function test_it_can_build_the_command_without_extra_options(): void
'--configuration',
$configPath,
],
$this->builder->build($configPath, '', [])
$this->builder->buildForInitialTestsRun($configPath, '')
);
}

Expand All @@ -75,14 +75,28 @@ public function test_it_can_build_the_command_with_extra_options(): void
'--verbose',
'--debug',
],
$this->builder->build($configPath, '--verbose --debug', [])
$this->builder->buildForInitialTestsRun($configPath, '--verbose --debug')
);
}

public function test_it_can_build_the_command_with_extra_options_that_contains_spaces(): void
{
$configPath = '/the config/path';

$this->assertSame(
[
'--configuration',
$configPath,
'--path=/a path/with spaces',
],
$this->builder->buildForInitialTestsRun($configPath, '--path=/a path/with spaces')
);
}

public function test_it_can_build_the_command_with_filter_option_for_covering_tests_for_mutant(): void
{
$configPath = '/the config/path';

$this->assertSame(
[
'--configuration',
Expand All @@ -91,7 +105,7 @@ public function test_it_can_build_the_command_with_extra_options_that_contains_s
'--filter',
'App\\\\Test::test_case1|App\\\\Test::test_case2',
],
$this->builder->build(
$this->builder->buildForMutant(
$configPath,
'--path=/a path/with spaces',
[
Expand Down

0 comments on commit 87efcb2

Please sign in to comment.