Skip to content

Commit

Permalink
[VarDumper] Disable links for IntelliJ platform
Browse files Browse the repository at this point in the history
  • Loading branch information
xabbuh authored and fabpot committed Mar 25, 2023
1 parent 7ec6e8b commit 3cd51fd
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Formatter/OutputFormatterStyle.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ public function apply(string $text)
{
if (null === $this->handlesHrefGracefully) {
$this->handlesHrefGracefully = 'JetBrains-JediTerm' !== getenv('TERMINAL_EMULATOR')
&& (!getenv('KONSOLE_VERSION') || (int) getenv('KONSOLE_VERSION') > 201100);
&& (!getenv('KONSOLE_VERSION') || (int) getenv('KONSOLE_VERSION') > 201100)
&& !isset($_SERVER['IDEA_INITIAL_DIRECTORY']);
}

if (null !== $this->href && $this->handlesHrefGracefully) {
Expand Down
45 changes: 42 additions & 3 deletions Tests/Formatter/OutputFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,14 @@ public function testFormatterHasStyles()
/**
* @dataProvider provideDecoratedAndNonDecoratedOutput
*/
public function testNotDecoratedFormatter(string $input, string $expectedNonDecoratedOutput, string $expectedDecoratedOutput, string $terminalEmulator = 'foo')
{
public function testNotDecoratedFormatterOnJediTermEmulator(
string $input,
string $expectedNonDecoratedOutput,
string $expectedDecoratedOutput,
bool $shouldBeJediTerm = false
) {
$terminalEmulator = $shouldBeJediTerm ? 'JetBrains-JediTerm' : 'Unknown';

$prevTerminalEmulator = getenv('TERMINAL_EMULATOR');
putenv('TERMINAL_EMULATOR='.$terminalEmulator);

Expand All @@ -258,6 +264,39 @@ public function testNotDecoratedFormatter(string $input, string $expectedNonDeco
}
}

/**
* @dataProvider provideDecoratedAndNonDecoratedOutput
*/
public function testNotDecoratedFormatterOnIDEALikeEnvironment(
string $input,
string $expectedNonDecoratedOutput,
string $expectedDecoratedOutput,
bool $expectsIDEALikeTerminal = false
) {
// Backup previous env variable
$previousValue = $_SERVER['IDEA_INITIAL_DIRECTORY'] ?? null;
$hasPreviousValue = \array_key_exists('IDEA_INITIAL_DIRECTORY', $_SERVER);

if ($expectsIDEALikeTerminal) {
$_SERVER['IDEA_INITIAL_DIRECTORY'] = __DIR__;
} elseif ($hasPreviousValue) {
// Forcibly remove the variable because the test runner may contain it
unset($_SERVER['IDEA_INITIAL_DIRECTORY']);
}

try {
$this->assertEquals($expectedDecoratedOutput, (new OutputFormatter(true))->format($input));
$this->assertEquals($expectedNonDecoratedOutput, (new OutputFormatter(false))->format($input));
} finally {
// Rollback previous env state
if ($hasPreviousValue) {
$_SERVER['IDEA_INITIAL_DIRECTORY'] = $previousValue;
} else {
unset($_SERVER['IDEA_INITIAL_DIRECTORY']);
}
}
}

public static function provideDecoratedAndNonDecoratedOutput()
{
return [
Expand All @@ -268,7 +307,7 @@ public static function provideDecoratedAndNonDecoratedOutput()
['<fg=red>some text with inline style</>', 'some text with inline style', "\033[31msome text with inline style\033[39m"],
['<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\\"],
['<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\\"],
['<href=idea://open/?file=/path/SomeFile.php&line=12>some URL</>', 'some URL', 'some URL', 'JetBrains-JediTerm'],
['<href=idea://open/?file=/path/SomeFile.php&line=12>some URL</>', 'some URL', 'some URL', true],
];
}

Expand Down

0 comments on commit 3cd51fd

Please sign in to comment.