diff --git a/src/TestFramework/AbstractTestFrameworkAdapter.php b/src/TestFramework/AbstractTestFrameworkAdapter.php index bea7cb635..dc9e19284 100644 --- a/src/TestFramework/AbstractTestFrameworkAdapter.php +++ b/src/TestFramework/AbstractTestFrameworkAdapter.php @@ -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) + ); } /** @@ -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 + ) ); } @@ -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 ); } diff --git a/src/TestFramework/CommandLineArgumentsAndOptionsBuilder.php b/src/TestFramework/CommandLineArgumentsAndOptionsBuilder.php index bb0372fcd..817c5b40f 100644 --- a/src/TestFramework/CommandLineArgumentsAndOptionsBuilder.php +++ b/src/TestFramework/CommandLineArgumentsAndOptionsBuilder.php @@ -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; } diff --git a/src/TestFramework/PhpUnit/CommandLine/ArgumentsAndOptionsBuilder.php b/src/TestFramework/PhpUnit/CommandLine/ArgumentsAndOptionsBuilder.php index 9659354fc..dbe8c778a 100644 --- a/src/TestFramework/PhpUnit/CommandLine/ArgumentsAndOptionsBuilder.php +++ b/src/TestFramework/PhpUnit/CommandLine/ArgumentsAndOptionsBuilder.php @@ -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', @@ -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) { diff --git a/tests/phpunit/TestFramework/PhpUnit/Adapter/PestAdapterTest.php b/tests/phpunit/TestFramework/PhpUnit/Adapter/PestAdapterTest.php index b46876f9a..bc5c85802 100644 --- a/tests/phpunit/TestFramework/PhpUnit/Adapter/PestAdapterTest.php +++ b/tests/phpunit/TestFramework/PhpUnit/Adapter/PestAdapterTest.php @@ -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') ; @@ -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', @@ -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', diff --git a/tests/phpunit/TestFramework/PhpUnit/Adapter/PhpUnitAdapterTest.php b/tests/phpunit/TestFramework/PhpUnit/Adapter/PhpUnitAdapterTest.php index 212fdc7ba..6410d8b5a 100644 --- a/tests/phpunit/TestFramework/PhpUnit/Adapter/PhpUnitAdapterTest.php +++ b/tests/phpunit/TestFramework/PhpUnit/Adapter/PhpUnitAdapterTest.php @@ -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') ; @@ -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', @@ -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', diff --git a/tests/phpunit/TestFramework/PhpUnit/CommandLine/ArgumentsAndOptionsBuilderTest.php b/tests/phpunit/TestFramework/PhpUnit/CommandLine/ArgumentsAndOptionsBuilderTest.php index a7440c9a4..cfa4b48e9 100644 --- a/tests/phpunit/TestFramework/PhpUnit/CommandLine/ArgumentsAndOptionsBuilderTest.php +++ b/tests/phpunit/TestFramework/PhpUnit/CommandLine/ArgumentsAndOptionsBuilderTest.php @@ -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, '') ); } @@ -75,7 +75,7 @@ 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') ); } @@ -83,6 +83,20 @@ public function test_it_can_build_the_command_with_extra_options_that_contains_s { $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', @@ -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', [