2121
2222use stdClass ;
2323use DateTimeImmutable ;
24- use Ergebnis \AgentDetector \Detector ;
2524use FastForward \DevTools \Console \Logger \OutputFormatLogger ;
2625use FastForward \DevTools \Console \Logger \Processor \CommandInputProcessor ;
2726use FastForward \DevTools \Console \Logger \Processor \CommandOutputProcessor ;
4342use Symfony \Component \Console \Output \OutputInterface ;
4443
4544use function Safe \json_decode ;
46- use function Safe \putenv ;
4745
4846#[CoversClass(OutputFormatLogger::class)]
4947#[UsesClass(CommandInputProcessor::class)]
@@ -65,29 +63,21 @@ final class OutputFormatLoggerTest extends TestCase
6563 */
6664 private ObjectProphecy $ environment ;
6765
68- /**
69- * @var array<string, mixed>
70- */
71- private array $ server ;
72-
73- private string |false $ composerTestsAreRunningEnv ;
74-
7566 /**
7667 * @return void
7768 */
7869 protected function setUp (): void
7970 {
80- $ this ->server = $ _SERVER ;
81- $ _SERVER = [];
82- $ this ->composerTestsAreRunningEnv = getenv ('COMPOSER_TESTS_ARE_RUNNING ' );
83- putenv ('COMPOSER_TESTS_ARE_RUNNING=1 ' );
84-
8571 $ this ->output = $ this ->prophesize (ConsoleOutputInterface::class);
8672 $ this ->errorOutput = $ this ->prophesize (OutputInterface::class);
8773 $ this ->clock = $ this ->prophesize (ClockInterface::class);
8874 $ this ->environment = $ this ->prophesize (RuntimeEnvironmentInterface::class);
8975 $ this ->environment ->isGithubActions ()
9076 ->willReturn (false );
77+ $ this ->environment ->isAgentPresent ()
78+ ->willReturn (false );
79+ $ this ->environment ->isComposerTestRun ()
80+ ->willReturn (false );
9181
9282 $ this ->output ->getErrorOutput ()
9383 ->willReturn ($ this ->errorOutput ->reveal ());
@@ -105,7 +95,7 @@ public function logWillWriteInterpolatedInfoMessagesToStandardOutput(): void
10595 new ArgvInput (['dev-tools ' ]),
10696 $ this ->output ->reveal (),
10797 $ this ->clock ->reveal (),
108- new Detector (),
98+ $ this -> environment -> reveal (),
10999 new CompositeContextProcessor ([new CommandInputProcessor (), new CommandOutputProcessor ()]),
110100 $ this ->createGithubActionOutput (),
111101 );
@@ -141,7 +131,7 @@ public function logWillWriteErrorMessagesToErrorOutput(): void
141131 new ArgvInput (['dev-tools ' ]),
142132 $ this ->output ->reveal (),
143133 $ this ->clock ->reveal (),
144- new Detector (),
134+ $ this -> environment -> reveal (),
145135 new CompositeContextProcessor ([new CommandInputProcessor (), new CommandOutputProcessor ()]),
146136 $ this ->createGithubActionOutput (),
147137 );
@@ -170,7 +160,7 @@ public function logWillWriteStructuredJsonWhenJsonOutputIsRequested(): void
170160 new ArgvInput (['dev-tools ' , '--json ' ]),
171161 $ this ->output ->reveal (),
172162 $ this ->clock ->reveal (),
173- new Detector (),
163+ $ this -> environment -> reveal (),
174164 new CompositeContextProcessor ([new CommandInputProcessor (), new CommandOutputProcessor ()]),
175165 $ this ->createGithubActionOutput (),
176166 );
@@ -197,7 +187,7 @@ public function logWillEmitParseableJsonWhenJsonOutputIsRequested(): void
197187 new ArgvInput (['dev-tools ' , '--json ' ]),
198188 $ this ->output ->reveal (),
199189 $ this ->clock ->reveal (),
200- new Detector (),
190+ $ this -> environment -> reveal (),
201191 new CompositeContextProcessor ([new CommandInputProcessor (), new CommandOutputProcessor ()]),
202192 $ this ->createGithubActionOutput (),
203193 );
@@ -223,7 +213,7 @@ public function logWillWritePrettyPrintedJsonWhenPrettyJsonOutputIsRequested():
223213 new ArgvInput (['dev-tools ' , '--pretty-json ' ]),
224214 $ this ->output ->reveal (),
225215 $ this ->clock ->reveal (),
226- new Detector (),
216+ $ this -> environment -> reveal (),
227217 new CompositeContextProcessor ([new CommandInputProcessor (), new CommandOutputProcessor ()]),
228218 $ this ->createGithubActionOutput (),
229219 );
@@ -250,7 +240,7 @@ public function logWillEmitParseableJsonWhenPrettyJsonOutputIsRequested(): void
250240 new ArgvInput (['dev-tools ' , '--pretty-json ' ]),
251241 $ this ->output ->reveal (),
252242 $ this ->clock ->reveal (),
253- new Detector (),
243+ $ this -> environment -> reveal (),
254244 new CompositeContextProcessor ([new CommandInputProcessor (), new CommandOutputProcessor ()]),
255245 $ this ->createGithubActionOutput (),
256246 );
@@ -276,7 +266,7 @@ public function logWillEmbedDecodedStructuredCommandOutputInsteadOfEscapedJsonSt
276266 new ArgvInput (['dev-tools ' , '--pretty-json ' ]),
277267 $ this ->output ->reveal (),
278268 $ this ->clock ->reveal (),
279- new Detector (),
269+ $ this -> environment -> reveal (),
280270 new CompositeContextProcessor ([new CommandInputProcessor (), new CommandOutputProcessor ()]),
281271 $ this ->createGithubActionOutput (),
282272 );
@@ -314,13 +304,16 @@ public function logWillEmbedDecodedStructuredCommandOutputInsteadOfEscapedJsonSt
314304 #[Test]
315305 public function logWillWriteStructuredJsonWhenAgentEnvironmentIsDetected (): void
316306 {
317- $ _SERVER ['CODEX_THREAD_ID ' ] = 'thread-123 ' ;
307+ $ this ->environment ->isAgentPresent ()
308+ ->willReturn (true );
309+ $ this ->environment ->isComposerTestRun ()
310+ ->willReturn (false );
318311
319312 $ logger = new OutputFormatLogger (
320313 new ArgvInput (['dev-tools ' ]),
321314 $ this ->output ->reveal (),
322315 $ this ->clock ->reveal (),
323- new Detector (),
316+ $ this -> environment -> reveal (),
324317 new CompositeContextProcessor ([new CommandInputProcessor (), new CommandOutputProcessor ()]),
325318 $ this ->createGithubActionOutput (),
326319 );
@@ -339,17 +332,29 @@ public function logWillWriteStructuredJsonWhenAgentEnvironmentIsDetected(): void
339332 /**
340333 * @return void
341334 */
342- protected function tearDown (): void
335+ #[Test]
336+ public function logWillKeepPlainTextOutputWhenAgentEnvironmentIsDetectedDuringComposerTests (): void
343337 {
344- $ _SERVER = $ this ->server ;
338+ $ this ->environment ->isAgentPresent ()
339+ ->willReturn (true );
340+ $ this ->environment ->isComposerTestRun ()
341+ ->willReturn (true );
345342
346- if (false === $ this ->composerTestsAreRunningEnv ) {
347- putenv ('COMPOSER_TESTS_ARE_RUNNING ' );
343+ $ logger = new OutputFormatLogger (
344+ new ArgvInput (['dev-tools ' ]),
345+ $ this ->output ->reveal (),
346+ $ this ->clock ->reveal (),
347+ $ this ->environment ->reveal (),
348+ new CompositeContextProcessor ([new CommandInputProcessor (), new CommandOutputProcessor ()]),
349+ $ this ->createGithubActionOutput (),
350+ );
348351
349- return ;
350- }
352+ $ this ->output ->writeln ('<info>2026-04-21T16:00:00+00:00 [INFO] Agent ready</info> ' )
353+ ->shouldBeCalledOnce ();
354+ $ this ->errorOutput ->writeln (Argument::type ('string ' ))
355+ ->shouldNotBeCalled ();
351356
352- putenv ( ' COMPOSER_TESTS_ARE_RUNNING= ' . $ this -> composerTestsAreRunningEnv );
357+ $ logger -> info ( ' Agent ready ' );
353358 }
354359
355360 /**
0 commit comments