diff --git a/Command/DumpCompletionCommand.php b/Command/DumpCompletionCommand.php index 1ad1c0e7b..6a322c929 100644 --- a/Command/DumpCompletionCommand.php +++ b/Command/DumpCompletionCommand.php @@ -52,10 +52,12 @@ protected function configure() default => ['~/.bashrc', "/etc/bash_completion.d/$commandName"], }; + $supportedShells = implode(', ', $this->getSupportedShells()); + $this ->setHelp(<<%command.name% command dumps the shell completion script required -to use shell autocompletion (currently, bash and fish completion is supported). +to use shell autocompletion (currently, {$supportedShells} completion are supported). Static installation ------------------- diff --git a/Formatter/OutputFormatterStyle.php b/Formatter/OutputFormatterStyle.php index 1659986ef..3394c9ada 100644 --- a/Formatter/OutputFormatterStyle.php +++ b/Formatter/OutputFormatterStyle.php @@ -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\\"; diff --git a/Tests/ApplicationTest.php b/Tests/ApplicationTest.php index d0b73389e..42534ddbd 100644 --- a/Tests/ApplicationTest.php +++ b/Tests/ApplicationTest.php @@ -733,7 +733,7 @@ public function testFindAlternativesOutput() public function testFindNamespaceDoesNotFailOnDeepSimilarNamespaces() { - $application = $this->getMockBuilder(Application::class)->setMethods(['getNamespaces'])->getMock(); + $application = $this->getMockBuilder(Application::class)->onlyMethods(['getNamespaces'])->getMock(); $application->expects($this->once()) ->method('getNamespaces') ->willReturn(['foo:sublong', 'bar:sub']); @@ -893,7 +893,7 @@ public function testRenderExceptionEscapesLines() public function testRenderExceptionLineBreaks() { - $application = $this->getMockBuilder(Application::class)->setMethods(['getTerminalWidth'])->getMock(); + $application = $this->getMockBuilder(Application::class)->addMethods(['getTerminalWidth'])->getMock(); $application->setAutoExit(false); $application->expects($this->any()) ->method('getTerminalWidth') @@ -1120,7 +1120,7 @@ public function testRunReturnsIntegerExitCode() { $exception = new \Exception('', 4); - $application = $this->getMockBuilder(Application::class)->setMethods(['doRun'])->getMock(); + $application = $this->getMockBuilder(Application::class)->onlyMethods(['doRun'])->getMock(); $application->setAutoExit(false); $application->expects($this->once()) ->method('doRun') @@ -1159,7 +1159,7 @@ public function testRunReturnsExitCodeOneForExceptionCodeZero() { $exception = new \Exception('', 0); - $application = $this->getMockBuilder(Application::class)->setMethods(['doRun'])->getMock(); + $application = $this->getMockBuilder(Application::class)->onlyMethods(['doRun'])->getMock(); $application->setAutoExit(false); $application->expects($this->once()) ->method('doRun') @@ -1202,7 +1202,7 @@ public function testRunReturnsExitCodeOneForNegativeExceptionCode($exceptionCode { $exception = new \Exception('', $exceptionCode); - $application = $this->getMockBuilder(Application::class)->setMethods(['doRun'])->getMock(); + $application = $this->getMockBuilder(Application::class)->onlyMethods(['doRun'])->getMock(); $application->setAutoExit(false); $application->expects($this->once()) ->method('doRun') diff --git a/Tests/Formatter/OutputFormatterTest.php b/Tests/Formatter/OutputFormatterTest.php index 9a1efc37c..20669e6d3 100644 --- a/Tests/Formatter/OutputFormatterTest.php +++ b/Tests/Formatter/OutputFormatterTest.php @@ -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); @@ -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 [ @@ -267,7 +298,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], ]; } diff --git a/composer.json b/composer.json index bafe5d165..6cc6166d5 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "symfony/console", "type": "library", "description": "Eases the creation of beautiful and testable command line interfaces", - "keywords": ["console", "cli", "command line", "terminal"], + "keywords": ["console", "cli", "command-line", "terminal"], "homepage": "https://symfony.com", "license": "MIT", "authors": [