Skip to content

Commit

Permalink
Merge branch '5.4' into 6.2
Browse files Browse the repository at this point in the history
* 5.4:
  [Cache] Removing null coalescing assignment operator on 5.4
  [Cache] Fix storing binary keys when using pgsql
  [FrameworkBundle] Add missing monolog channel tag for messenger services
  [FrameworkBundle] Improve documentation about translation:extract --sort option
  [VarDumper] Disable links for IntelliJ platform
  [Notifier] Add bridge documentation
  [HttpClient] Add hint about `timeout` and `max_duration` options
  [HttpFoundation] Use separate caches for IpUtils checkIp4 and checkIp6
  [FrameworkBundle] Fix wiring session.handler when handler_id is null
  [FrameworkBundle] Workflow - Fix LogicException about a wrong configuration of "enabled" node
  • Loading branch information
nicolas-grekas committed Mar 29, 2023
2 parents 85e2e03 + 3cd51fd commit 3582d68
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Formatter/OutputFormatterStyle.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ public function setOptions(array $options)
public function apply(string $text): string
{
$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) {
$text = "\033]8;;$this->href\033\\$text\033]8;;\033\\";
Expand Down
35 changes: 33 additions & 2 deletions Tests/Formatter/OutputFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,10 @@ 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 @@ -257,6 +259,35 @@ 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 @@ -267,7 +298,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 3582d68

Please sign in to comment.