@@ -245,8 +245,14 @@ public function testFormatterHasStyles()
245245 /**
246246 * @dataProvider provideDecoratedAndNonDecoratedOutput
247247 */
248- public function testNotDecoratedFormatter (string $ input , string $ expectedNonDecoratedOutput , string $ expectedDecoratedOutput , string $ terminalEmulator = 'foo ' )
249- {
248+ public function testNotDecoratedFormatterOnJediTermEmulator (
249+ string $ input ,
250+ string $ expectedNonDecoratedOutput ,
251+ string $ expectedDecoratedOutput ,
252+ bool $ shouldBeJediTerm = false
253+ ) {
254+ $ terminalEmulator = $ shouldBeJediTerm ? 'JetBrains-JediTerm ' : 'Unknown ' ;
255+
250256 $ prevTerminalEmulator = getenv ('TERMINAL_EMULATOR ' );
251257 putenv ('TERMINAL_EMULATOR= ' .$ terminalEmulator );
252258
@@ -258,6 +264,39 @@ public function testNotDecoratedFormatter(string $input, string $expectedNonDeco
258264 }
259265 }
260266
267+ /**
268+ * @dataProvider provideDecoratedAndNonDecoratedOutput
269+ */
270+ public function testNotDecoratedFormatterOnIDEALikeEnvironment (
271+ string $ input ,
272+ string $ expectedNonDecoratedOutput ,
273+ string $ expectedDecoratedOutput ,
274+ bool $ expectsIDEALikeTerminal = false
275+ ) {
276+ // Backup previous env variable
277+ $ previousValue = $ _SERVER ['IDEA_INITIAL_DIRECTORY ' ] ?? null ;
278+ $ hasPreviousValue = \array_key_exists ('IDEA_INITIAL_DIRECTORY ' , $ _SERVER );
279+
280+ if ($ expectsIDEALikeTerminal ) {
281+ $ _SERVER ['IDEA_INITIAL_DIRECTORY ' ] = __DIR__ ;
282+ } elseif ($ hasPreviousValue ) {
283+ // Forcibly remove the variable because the test runner may contain it
284+ unset($ _SERVER ['IDEA_INITIAL_DIRECTORY ' ]);
285+ }
286+
287+ try {
288+ $ this ->assertEquals ($ expectedDecoratedOutput , (new OutputFormatter (true ))->format ($ input ));
289+ $ this ->assertEquals ($ expectedNonDecoratedOutput , (new OutputFormatter (false ))->format ($ input ));
290+ } finally {
291+ // Rollback previous env state
292+ if ($ hasPreviousValue ) {
293+ $ _SERVER ['IDEA_INITIAL_DIRECTORY ' ] = $ previousValue ;
294+ } else {
295+ unset($ _SERVER ['IDEA_INITIAL_DIRECTORY ' ]);
296+ }
297+ }
298+ }
299+
261300 public static function provideDecoratedAndNonDecoratedOutput ()
262301 {
263302 return [
@@ -268,7 +307,7 @@ public static function provideDecoratedAndNonDecoratedOutput()
268307 ['<fg=red>some text with inline style</> ' , 'some text with inline style ' , "\033[31msome text with inline style \033[39m " ],
269308 ['<href=idea://open/?file=/path/SomeFile.php&line=12>some URL</> ' , 'some URL ' , "\033]8;;idea://open/?file=/path/SomeFile.php&line=12 \033\\some URL \033]8;; \033\\" ],
270309 ['<href=https://example.com/\<woohoo\>>some URL with \<woohoo\></> ' , 'some URL with <woohoo> ' , "\033]8;;https://example.com/<woohoo> \033\\some URL with <woohoo> \033]8;; \033\\" ],
271- ['<href=idea://open/?file=/path/SomeFile.php&line=12>some URL</> ' , 'some URL ' , 'some URL ' , ' JetBrains-JediTerm ' ],
310+ ['<href=idea://open/?file=/path/SomeFile.php&line=12>some URL</> ' , 'some URL ' , 'some URL ' , true ],
272311 ];
273312 }
274313
0 commit comments