From 3cd51fd2e6c461ca678f84d419461281bd87a0a8 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Fri, 3 Feb 2023 10:25:44 +0100 Subject: [PATCH] [VarDumper] Disable links for IntelliJ platform --- Formatter/OutputFormatterStyle.php | 3 +- Tests/Formatter/OutputFormatterTest.php | 45 +++++++++++++++++++++++-- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/Formatter/OutputFormatterStyle.php b/Formatter/OutputFormatterStyle.php index 0fb36ac63..8370ba058 100644 --- a/Formatter/OutputFormatterStyle.php +++ b/Formatter/OutputFormatterStyle.php @@ -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) { diff --git a/Tests/Formatter/OutputFormatterTest.php b/Tests/Formatter/OutputFormatterTest.php index 84eb8d87f..203f5a3ca 100644 --- a/Tests/Formatter/OutputFormatterTest.php +++ b/Tests/Formatter/OutputFormatterTest.php @@ -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); @@ -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 [ @@ -268,7 +307,7 @@ public static function provideDecoratedAndNonDecoratedOutput() ['some text with inline style', 'some text with inline style', "\033[31msome text with inline style\033[39m"], ['some URL', 'some URL', "\033]8;;idea://open/?file=/path/SomeFile.php&line=12\033\\some URL\033]8;;\033\\"], ['>some URL with \', 'some URL with ', "\033]8;;https://example.com/\033\\some URL with \033]8;;\033\\"], - ['some URL', 'some URL', 'some URL', 'JetBrains-JediTerm'], + ['some URL', 'some URL', 'some URL', true], ]; }