Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3cd51fd

Browse files
xabbuhfabpot
authored andcommitted
[VarDumper] Disable links for IntelliJ platform
1 parent 7ec6e8b commit 3cd51fd

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

Formatter/OutputFormatterStyle.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ public function apply(string $text)
9696
{
9797
if (null === $this->handlesHrefGracefully) {
9898
$this->handlesHrefGracefully = 'JetBrains-JediTerm' !== getenv('TERMINAL_EMULATOR')
99-
&& (!getenv('KONSOLE_VERSION') || (int) getenv('KONSOLE_VERSION') > 201100);
99+
&& (!getenv('KONSOLE_VERSION') || (int) getenv('KONSOLE_VERSION') > 201100)
100+
&& !isset($_SERVER['IDEA_INITIAL_DIRECTORY']);
100101
}
101102

102103
if (null !== $this->href && $this->handlesHrefGracefully) {

Tests/Formatter/OutputFormatterTest.php

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)