diff --git a/src/Command/InfectionCommand.php b/src/Command/InfectionCommand.php index 95f9a7e31..d6312a22a 100644 --- a/src/Command/InfectionCommand.php +++ b/src/Command/InfectionCommand.php @@ -219,7 +219,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $processBuilder = new ProcessBuilder($adapter, $config->getProcessTimeout()); $testFrameworkOptions = $this->getTestFrameworkExtraOptions($testFrameworkKey); - $initialTestsRunner = new InitialTestsRunner($processBuilder, $this->eventDispatcher); + $initialTestsRunner = new InitialTestsRunner($processBuilder, $this->eventDispatcher, $metricsCalculator); $initialTestSuitProcess = $initialTestsRunner->run( $testFrameworkOptions->getForInitialProcess(), $this->skipCoverage, diff --git a/src/Logger/DebugFileLogger.php b/src/Logger/DebugFileLogger.php index 83320cdec..c39e2561c 100644 --- a/src/Logger/DebugFileLogger.php +++ b/src/Logger/DebugFileLogger.php @@ -68,6 +68,18 @@ protected function getLogLines(): array 'Not Covered' ); + if (!empty($this->metricsCalculator->getDebugInfo())) { + $logs[] = ''; + $logs[] = 'Debug Messages:'; + $logs[] = '==============='; + $logs[] = ''; + + foreach ($this->metricsCalculator->getDebugInfo() as $line) { + $logs[] = ''; + $logs[] = $line; + } + } + return $logs; } diff --git a/src/Mutant/MetricsCalculator.php b/src/Mutant/MetricsCalculator.php index d4200875e..b5e322a73 100644 --- a/src/Mutant/MetricsCalculator.php +++ b/src/Mutant/MetricsCalculator.php @@ -98,6 +98,11 @@ class MetricsCalculator */ private $totalMutantsCount = 0; + /** + * @var string[] + */ + private $debugMessage = []; + /** * Build a metric calculator with a sub-set of mutators * @@ -274,4 +279,17 @@ public function getErrorProcesses(): array { return $this->errorProcesses; } + + public function addDebugInfo(string $msg): void + { + $this->debugMessage[] = $msg; + } + + /** + * @return string[] + */ + public function getDebugInfo(): array + { + return $this->debugMessage; + } } diff --git a/src/Process/Runner/InitialTestsRunner.php b/src/Process/Runner/InitialTestsRunner.php index 2108cc00f..db105c4ca 100644 --- a/src/Process/Runner/InitialTestsRunner.php +++ b/src/Process/Runner/InitialTestsRunner.php @@ -39,6 +39,7 @@ use Infection\Events\InitialTestCaseCompleted; use Infection\Events\InitialTestSuiteFinished; use Infection\Events\InitialTestSuiteStarted; +use Infection\Mutant\MetricsCalculator; use Infection\Process\Builder\ProcessBuilder; use Symfony\Component\Process\Process; @@ -57,10 +58,16 @@ final class InitialTestsRunner */ private $eventDispatcher; - public function __construct(ProcessBuilder $processBuilder, EventDispatcherInterface $eventDispatcher) + /** + * @var MetricsCalculator + */ + private $metrics; + + public function __construct(ProcessBuilder $processBuilder, EventDispatcherInterface $eventDispatcher, MetricsCalculator $metrics) { $this->processBuilder = $processBuilder; $this->eventDispatcher = $eventDispatcher; + $this->metrics = $metrics; } public function run(string $testFrameworkExtraOptions, bool $skipCoverage, array $phpExtraOptions = []): Process @@ -73,6 +80,20 @@ public function run(string $testFrameworkExtraOptions, bool $skipCoverage, array $this->eventDispatcher->dispatch(new InitialTestSuiteStarted()); + $cmd = $process->getCommandLine(); + + if (!empty($cmd)) { + $this->metrics->addDebugInfo( + sprintf( + '[%s()] Command:%s%s%s', + __METHOD__, + PHP_EOL, + $cmd, + PHP_EOL + ) + ); + } + $process->run(function ($type) use ($process): void { if ($process::ERR === $type) { $process->stop(); diff --git a/tests/Console/E2ETest.php b/tests/Console/E2ETest.php index 039c36d89..762e1f245 100644 --- a/tests/Console/E2ETest.php +++ b/tests/Console/E2ETest.php @@ -172,7 +172,14 @@ private function runOnE2EFixture($path): string $this->markTestSkipped('Saved golden output'); } - $this->assertFileEquals('expected-output.txt', 'infection.log', sprintf('%s/expected-output.txt is not same as infection.log (if that is OK, run GOLDEN=1 vendor/bin/phpunit)', getcwd())); + $this->assertStringStartsWith( + file_get_contents('expected-output.txt'), + file_get_contents('infection.log'), + sprintf( + '%s/expected-output.txt is not same as infection.log (if that is OK, run GOLDEN=1 vendor/bin/phpunit)', + getcwd() + ) + ); return $output; } diff --git a/tests/Mutant/MetricsCalculatorTest.php b/tests/Mutant/MetricsCalculatorTest.php index f0b240554..9d87f689e 100644 --- a/tests/Mutant/MetricsCalculatorTest.php +++ b/tests/Mutant/MetricsCalculatorTest.php @@ -65,6 +65,8 @@ public function test_it_shows_zero_values_by_default(): void $this->assertSame(0.0, $calculator->getMutationScoreIndicator()); $this->assertSame(0.0, $calculator->getCoverageRate()); $this->assertSame(0.0, $calculator->getCoveredCodeMutationScoreIndicator()); + + $this->assertSame([], $calculator->getDebugInfo()); } public function test_it_collects_all_values(): void diff --git a/tests/Process/Runner/InitialTestsRunnerTest.php b/tests/Process/Runner/InitialTestsRunnerTest.php index df13bd166..1c6ad6947 100644 --- a/tests/Process/Runner/InitialTestsRunnerTest.php +++ b/tests/Process/Runner/InitialTestsRunnerTest.php @@ -39,6 +39,7 @@ use Infection\Events\InitialTestCaseCompleted; use Infection\Events\InitialTestSuiteFinished; use Infection\Events\InitialTestSuiteStarted; +use Infection\Mutant\MetricsCalculator; use Infection\Process\Builder\ProcessBuilder; use Infection\Process\Runner\InitialTestsRunner; use PHPUnit\Framework\MockObject\MockObject; @@ -78,7 +79,10 @@ public function test_it_dispatches_events(): void $this->isInstanceOf(InitialTestSuiteFinished::class) ); - $testRunner = new InitialTestsRunner($processBuilder, $eventDispatcher); + $metrics = $this->getMockBuilder(MetricsCalculator::class)->getMock(); + $metrics->method('getDebugInfo')->willReturn(['test']); + + $testRunner = new InitialTestsRunner($processBuilder, $eventDispatcher, $metrics); $testRunner->run('', false); }