diff --git a/src/Events/InitialTestSuiteFinished.php b/src/Events/InitialTestSuiteFinished.php index 155181131..619a27fb5 100644 --- a/src/Events/InitialTestSuiteFinished.php +++ b/src/Events/InitialTestSuiteFinished.php @@ -40,4 +40,18 @@ */ final class InitialTestSuiteFinished { + /** + * @var string + */ + private $outputText; + + public function __construct(string $outputText) + { + $this->outputText = $outputText; + } + + public function getOutputText(): string + { + return $this->outputText; + } } diff --git a/src/Process/Builder/SubscriberBuilder.php b/src/Process/Builder/SubscriberBuilder.php index 58e1eeaa4..5d7d135c7 100644 --- a/src/Process/Builder/SubscriberBuilder.php +++ b/src/Process/Builder/SubscriberBuilder.php @@ -228,7 +228,7 @@ private function getInitialTestsConsoleLoggerSubscriber(AbstractTestFrameworkAda return new CiInitialTestsConsoleLoggerSubscriber($output, $testFrameworkAdapter); } - return new InitialTestsConsoleLoggerSubscriber($output, $testFrameworkAdapter); + return new InitialTestsConsoleLoggerSubscriber($output, $testFrameworkAdapter, $this->input->getOption('debug')); } private function shouldSkipProgressBars(): bool diff --git a/src/Process/Listener/InitialTestsConsoleLoggerSubscriber.php b/src/Process/Listener/InitialTestsConsoleLoggerSubscriber.php index 17e516fbb..1d2a68789 100644 --- a/src/Process/Listener/InitialTestsConsoleLoggerSubscriber.php +++ b/src/Process/Listener/InitialTestsConsoleLoggerSubscriber.php @@ -63,10 +63,16 @@ final class InitialTestsConsoleLoggerSubscriber implements EventSubscriberInterf */ private $testFrameworkAdapter; - public function __construct(OutputInterface $output, AbstractTestFrameworkAdapter $testFrameworkAdapter) + /** + * @var bool + */ + private $debug; + + public function __construct(OutputInterface $output, AbstractTestFrameworkAdapter $testFrameworkAdapter, bool $debug) { $this->output = $output; $this->testFrameworkAdapter = $testFrameworkAdapter; + $this->debug = $debug; $this->progressBar = new ProgressBar($this->output); $this->progressBar->setFormat('verbose'); @@ -105,6 +111,10 @@ public function onInitialTestSuiteStarted(InitialTestSuiteStarted $event): void public function onInitialTestSuiteFinished(InitialTestSuiteFinished $event): void { $this->progressBar->finish(); + + if ($this->debug) { + $this->output->writeln(PHP_EOL . $event->getOutputText()); + } } public function onInitialTestCaseCompleted(InitialTestCaseCompleted $event): void diff --git a/src/Process/Runner/InitialTestsRunner.php b/src/Process/Runner/InitialTestsRunner.php index 1c35a91fb..79d597ca4 100644 --- a/src/Process/Runner/InitialTestsRunner.php +++ b/src/Process/Runner/InitialTestsRunner.php @@ -81,7 +81,7 @@ public function run(string $testFrameworkExtraOptions, bool $skipCoverage, array $this->eventDispatcher->dispatch(new InitialTestCaseCompleted()); }); - $this->eventDispatcher->dispatch(new InitialTestSuiteFinished()); + $this->eventDispatcher->dispatch(new InitialTestSuiteFinished($process->getOutput())); return $process; } diff --git a/tests/Events/InitialTestSuiteFinishedTest.php b/tests/Events/InitialTestSuiteFinishedTest.php index 911d088cd..e247ef29b 100644 --- a/tests/Events/InitialTestSuiteFinishedTest.php +++ b/tests/Events/InitialTestSuiteFinishedTest.php @@ -43,12 +43,12 @@ */ final class InitialTestSuiteFinishedTest extends TestCase { - /** - * This class is only used to fire events, and the only functionality it needs is being instantiated - */ - public function test_it_can_be_initialzed(): void + public function test_it_passes_the_output_along(): void { - $class = new InitialTestSuiteFinished(); - $this->assertInstanceOf(InitialTestSuiteFinished::class, $class); + $text = 'foo-bar-baz'; + + $class = new InitialTestSuiteFinished($text); + + $this->assertSame($text, $class->getOutputText()); } } diff --git a/tests/Process/Builder/SubscriberBuilderTest.php b/tests/Process/Builder/SubscriberBuilderTest.php index 66a34b6be..85ed5a60f 100644 --- a/tests/Process/Builder/SubscriberBuilderTest.php +++ b/tests/Process/Builder/SubscriberBuilderTest.php @@ -51,6 +51,10 @@ /** * @internal + * + * NOTE: + * InputInterfaces should be mocked here so that the 'getOption' method with paramater 'no-progress' + * should return true. Otherwise you will see different results based on wheter its running in CI or not. */ final class SubscriberBuilderTest extends TestCase { @@ -61,7 +65,7 @@ public function test_it_registers_the_subscribers_when_debugging(): void ->method('getOption') ->will($this->returnValueMap( [ - ['ci-friendly', false], + ['no-progress', true], ['formatter', 'progress'], ['show-mutations', true], ['log-verbosity', 'all'], @@ -99,7 +103,7 @@ public function test_it_registers_the_subscribers_when_not_debugging(): void ->method('getOption') ->will($this->returnValueMap( [ - ['ci-friendly', false], + ['no-progress', true], ['formatter', 'progress'], ['show-mutations', true], ['log-verbosity', 'all'], @@ -137,9 +141,10 @@ public function test_it_throws_an_exception_when_output_formatter_is_invalid(): ->method('getOption') ->will($this->returnValueMap( [ - ['ci-friendly', false], + ['no-progress', true], ['formatter', 'foo'], ['show-mutations', true], + ['debug', true], ] )); $calculator = new MetricsCalculator(); diff --git a/tests/Process/Listener/InitialTestsConsoleLoggerSubscriberTest.php b/tests/Process/Listener/InitialTestsConsoleLoggerSubscriberTest.php index 0f9bd8f5f..5c433c7c7 100644 --- a/tests/Process/Listener/InitialTestsConsoleLoggerSubscriberTest.php +++ b/tests/Process/Listener/InitialTestsConsoleLoggerSubscriberTest.php @@ -36,6 +36,7 @@ namespace Infection\Tests\Process\Listener; use Infection\EventDispatcher\EventDispatcher; +use Infection\Events\InitialTestSuiteFinished; use Infection\Events\InitialTestSuiteStarted; use Infection\Process\Listener\InitialTestsConsoleLoggerSubscriber; use Infection\TestFramework\AbstractTestFrameworkAdapter; @@ -58,7 +59,7 @@ public function test_it_reacts_on_initial_test_suite_run(): void ->method('getVersion'); $dispatcher = new EventDispatcher(); - $dispatcher->addSubscriber(new InitialTestsConsoleLoggerSubscriber($output, $testFramework)); + $dispatcher->addSubscriber(new InitialTestsConsoleLoggerSubscriber($output, $testFramework, false)); $dispatcher->dispatch(new InitialTestSuiteStarted()); } @@ -85,8 +86,27 @@ public function test_it_sets_test_framework_version_as_unknown_in_case_of_except ->will($this->throwException(new \InvalidArgumentException())); $dispatcher = new EventDispatcher(); - $dispatcher->addSubscriber(new InitialTestsConsoleLoggerSubscriber($output, $testFramework)); + $dispatcher->addSubscriber(new InitialTestsConsoleLoggerSubscriber($output, $testFramework, false)); $dispatcher->dispatch(new InitialTestSuiteStarted()); } + + public function test_it_outputs_the_initial_process_text_if_in_debug_mode(): void + { + $processText = 'PHPUnit Test suite ...'; + $output = $this->createMock(OutputInterface::class); + $output->expects($this->once()) + ->method('writeln') + ->with(PHP_EOL . $processText); + + $output->method('getVerbosity') + ->willReturn(OutputInterface::VERBOSITY_QUIET); + + $testFramework = $this->createMock(AbstractTestFrameworkAdapter::class); + + $dispatcher = new EventDispatcher(); + $dispatcher->addSubscriber(new InitialTestsConsoleLoggerSubscriber($output, $testFramework, true)); + + $dispatcher->dispatch(new InitialTestSuiteFinished($processText)); + } } diff --git a/tests/Process/Runner/InitialTestsRunnerTest.php b/tests/Process/Runner/InitialTestsRunnerTest.php index ef0a0d45f..4cb8297fb 100644 --- a/tests/Process/Runner/InitialTestsRunnerTest.php +++ b/tests/Process/Runner/InitialTestsRunnerTest.php @@ -62,6 +62,9 @@ public function test_it_dispatches_events(): void return true; })); + $process->expects($this->once()) + ->method('getOutput') + ->willReturn('foo'); $processBuilder = $this->createMock(ProcessBuilder::class); $processBuilder->method('getProcessForInitialTestRun')