Skip to content

Commit

Permalink
Merge branch '4.4' into 5.2
Browse files Browse the repository at this point in the history
* 4.4:
  [Console] Escape synopsis output
  Document null support in NumberToLocalizedStringTransformer
  • Loading branch information
nicolas-grekas committed Jun 3, 2021
2 parents 9e18ae5 + e3d2125 commit 3685a3a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Application.php
Expand Up @@ -795,7 +795,7 @@ public function renderThrowable(\Throwable $e, OutputInterface $output): void
$this->doRenderThrowable($e, $output);

if (null !== $this->runningCommand) {
$output->writeln(sprintf('<info>%s</info>', sprintf($this->runningCommand->getSynopsis(), $this->getName())), OutputInterface::VERBOSITY_QUIET);
$output->writeln(sprintf('<info>%s</info>', OutputFormatter::escape(sprintf($this->runningCommand->getSynopsis(), $this->getName()))), OutputInterface::VERBOSITY_QUIET);
$output->writeln('', OutputInterface::VERBOSITY_QUIET);
}
}
Expand Down
17 changes: 17 additions & 0 deletions Tests/ApplicationTest.php
Expand Up @@ -927,6 +927,23 @@ public function testRenderExceptionStackTraceContainsRootException()
$this->assertStringContainsString('Dummy type "class@anonymous" is invalid.', $tester->getDisplay(true));
}

public function testRenderExceptionEscapesLinesOfSynopsis()
{
$application = new Application();
$application->setAutoExit(false);
$application
->register('foo')
->setCode(function () {
throw new \Exception('some exception');
})
->addArgument('info')
;
$tester = new ApplicationTester($application);

$tester->run(['command' => 'foo'], ['decorated' => false]);
$this->assertStringMatchesFormatFile(self::$fixturesPath.'/application_rendersynopsis_escapesline.txt', $tester->getDisplay(true), '->renderException() escapes lines containing formatting of synopsis');
}

public function testRun()
{
$application = new Application();
Expand Down
3 changes: 2 additions & 1 deletion Tests/Command/CommandTest.php
Expand Up @@ -185,7 +185,8 @@ public function testGetSynopsis()
$command = new \TestCommand();
$command->addOption('foo');
$command->addArgument('bar');
$this->assertEquals('namespace:name [--foo] [--] [<bar>]', $command->getSynopsis(), '->getSynopsis() returns the synopsis');
$command->addArgument('info');
$this->assertEquals('namespace:name [--foo] [--] [<bar> [<info>]]', $command->getSynopsis(), '->getSynopsis() returns the synopsis');
}

public function testAddGetUsages()
Expand Down
7 changes: 7 additions & 0 deletions Tests/Fixtures/application_rendersynopsis_escapesline.txt
@@ -0,0 +1,7 @@

In ApplicationTest.php line %d:

some exception


foo [<info>]

0 comments on commit 3685a3a

Please sign in to comment.