Skip to content

Commit f995db4

Browse files
xabbuhfabpot
authored andcommitted
[VarDumper] Disable links for IntelliJ platform
1 parent b181772 commit f995db4

File tree

3 files changed

+46
-5
lines changed

3 files changed

+46
-5
lines changed

src/Symfony/Component/Console/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) {

src/Symfony/Component/Console/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

src/Symfony/Component/VarDumper/Dumper/CliDumper.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,8 @@ protected function style(string $style, string $value, array $attr = [])
448448

449449
if (null === $this->handlesHrefGracefully) {
450450
$this->handlesHrefGracefully = 'JetBrains-JediTerm' !== getenv('TERMINAL_EMULATOR')
451-
&& (!getenv('KONSOLE_VERSION') || (int) getenv('KONSOLE_VERSION') > 201100);
451+
&& (!getenv('KONSOLE_VERSION') || (int) getenv('KONSOLE_VERSION') > 201100)
452+
&& !isset($_SERVER['IDEA_INITIAL_DIRECTORY']);
452453
}
453454

454455
if (isset($attr['ellipsis'], $attr['ellipsis-type'])) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy