@@ -245,8 +245,14 @@ public function testFormatterHasStyles()
245
245
/**
246
246
* @dataProvider provideDecoratedAndNonDecoratedOutput
247
247
*/
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
+
250
256
$ prevTerminalEmulator = getenv ('TERMINAL_EMULATOR ' );
251
257
putenv ('TERMINAL_EMULATOR= ' .$ terminalEmulator );
252
258
@@ -258,6 +264,39 @@ public function testNotDecoratedFormatter(string $input, string $expectedNonDeco
258
264
}
259
265
}
260
266
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
+
261
300
public static function provideDecoratedAndNonDecoratedOutput ()
262
301
{
263
302
return [
@@ -268,7 +307,7 @@ public static function provideDecoratedAndNonDecoratedOutput()
268
307
['<fg=red>some text with inline style</> ' , 'some text with inline style ' , "\033[31msome text with inline style \033[39m " ],
269
308
['<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\\" ],
270
309
['<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 ],
272
311
];
273
312
}
274
313
0 commit comments