[Console] Escape synopsis output
This commit is contained in:
parent
53d9b105a0
commit
960cb520df
@ -833,7 +833,7 @@ class Application implements ResetInterface
|
|||||||
private function finishRenderThrowableOrException(OutputInterface $output): void
|
private function finishRenderThrowableOrException(OutputInterface $output): void
|
||||||
{
|
{
|
||||||
if (null !== $this->runningCommand) {
|
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);
|
$output->writeln('', OutputInterface::VERBOSITY_QUIET);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -940,6 +940,23 @@ class ApplicationTest extends TestCase
|
|||||||
$this->assertStringContainsString('Dummy type "class@anonymous" is invalid.', $tester->getDisplay(true));
|
$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()
|
public function testRun()
|
||||||
{
|
{
|
||||||
$application = new Application();
|
$application = new Application();
|
||||||
|
@ -192,7 +192,8 @@ class CommandTest extends TestCase
|
|||||||
$command = new \TestCommand();
|
$command = new \TestCommand();
|
||||||
$command->addOption('foo');
|
$command->addOption('foo');
|
||||||
$command->addArgument('bar');
|
$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()
|
public function testAddGetUsages()
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
|
||||||
|
In ApplicationTest.php line %d:
|
||||||
|
|
||||||
|
some exception
|
||||||
|
|
||||||
|
|
||||||
|
foo [<info>]
|
Reference in New Issue
Block a user