55namespace Testo \Bridge \Symfony \Renderer ;
66
77use Testo \Assert \TestState ;
8+ use Testo \Common \Environment ;
89use Testo \Core \Context \CaseInfo ;
910use Testo \Core \Context \CaseResult ;
1011use Testo \Core \Context \SuiteInfo ;
@@ -39,9 +40,6 @@ final class TerminalLogger
3940 /** @var list<array{result: TestResult, duration: int<0, max>|null}> */
4041 private array $ failures = [];
4142
42- private float $ startTime ;
43- private bool $ headerPrinted = false ;
44-
4543 /**
4644 * Current indentation level for nested tests (e.g., DataProvider datasets).
4745 *
@@ -56,16 +54,13 @@ final class TerminalLogger
5654
5755 public function __construct (
5856 private readonly OutputFormat $ format = OutputFormat::Compact,
59- ) {
60- $ this ->startTime = \microtime (true );
61- }
57+ ) {}
6258
6359 /**
6460 * Publishes test suite started message.
6561 */
6662 public function suiteStartedFromInfo (SuiteInfo $ info ): void
6763 {
68- $ this ->ensureHeader ();
6964 echo Formatter::suiteHeader ($ info ->name , $ this ->format );
7065 }
7166
@@ -82,7 +77,6 @@ public function handleSuiteResult(SuiteInfo $info, SuiteResult $result): void
8277 */
8378 public function caseStartedFromInfo (CaseInfo $ info ): void
8479 {
85- $ this ->ensureHeader ();
8680 echo Formatter::caseHeader ($ info ->name , $ this ->format );
8781 }
8882
@@ -100,7 +94,6 @@ public function handleCaseResult(CaseInfo $info, CaseResult $result): void
10094 */
10195 public function batchStartedFromInfo (TestInfo $ info ): void
10296 {
103- $ this ->ensureHeader ();
10497 $ this ->currentIndentLevel = 1 ;
10598
10699 if ($ this ->format === OutputFormat::Dots) {
@@ -129,7 +122,6 @@ public function batchFinishedFromInfo(TestInfo $info): void
129122 */
130123 public function testStartedFromInfo (TestInfo $ info , ?string $ overrideName = null ): void
131124 {
132- $ this ->ensureHeader ();
133125 $ this ->currentTestName = $ overrideName ;
134126 // No output on test start for compact/dots mode
135127 }
@@ -154,23 +146,39 @@ public function handleTestResult(TestResult $result, ?int $duration): void
154146 /**
155147 * Prints final summary with all failures and statistics.
156148 */
157- public function printSummary (): void
149+ public function printSummary (float $ duration ): void
158150 {
159151 $ this ->printFailures ();
160- $ this ->printStatistics ();
152+ $ this ->printStatistics ($ duration );
161153 }
162154
163155 /**
164156 * Ensures run header is printed once.
165157 */
166- private function ensureHeader (): void
158+ public function ensureHeader (): void
167159 {
168- if ($ this ->headerPrinted ) {
169- return ;
170- }
171-
172160 echo Formatter::runHeader ();
173- $ this ->headerPrinted = true ;
161+ }
162+
163+ public function printEnvironment (): void
164+ {
165+ echo \sprintf (' %s %s (%s) ' , Style::info ('OS: ' ), Environment::getOs (), Environment::getCpu ()) . "\n" ;
166+ echo \sprintf (' %s %s (%s, memory: %s) ' , Style::info ('PHP: ' ), Environment::getPhpVersion (), \PHP_SAPI , \ini_get ('memory_limit ' ) ?: 'unlimited ' ) . "\n" ;
167+
168+ $ modes = Environment::getXDebugMode ();
169+ $ xdebug = match (true ) {
170+ !Environment::hasXDebug () => 'off ' ,
171+ $ modes !== [] => Environment::getXDebugVersion () . Style::dim (' ( ' . \implode (', ' , $ modes ) . ') ' ),
172+ default => Environment::getXDebugVersion () . Style::dim (' (off) ' ),
173+ };
174+ echo \sprintf (' %s %s ' , Style::info ('XDebug: ' ), $ xdebug ) . "\n" ;
175+
176+ $ opcache = match (true ) {
177+ !Environment::isOpCacheEnabled () => 'off ' ,
178+ Environment::isJitEnabled () => 'enabled with JIT ' ,
179+ default => 'enabled ' ,
180+ };
181+ echo \sprintf (' %s %s ' , Style::info ('OPcache: ' ), $ opcache ) . "\n\n" ;
174182 }
175183
176184 /**
@@ -348,9 +356,8 @@ function: $result->info->testDefinition->reflection,
348356 /**
349357 * Prints final statistics.
350358 */
351- private function printStatistics (): void
359+ private function printStatistics (float $ duration ): void
352360 {
353- $ duration = \microtime (true ) - $ this ->startTime ;
354361 $ success = $ this ->failedTests === 0 ;
355362
356363 echo Formatter::summary (
0 commit comments