Render all line breaks according to the exception message
This commit is contained in:
parent
800f306589
commit
e2d4904a84
@ -681,7 +681,7 @@ class Application
|
|||||||
$width = 1 << 31;
|
$width = 1 << 31;
|
||||||
}
|
}
|
||||||
$lines = array();
|
$lines = array();
|
||||||
foreach (preg_split('/\r?\n/', $e->getMessage()) as $line) {
|
foreach (preg_split('/\r?\n/', trim($e->getMessage())) as $line) {
|
||||||
foreach ($this->splitStringByWidth($line, $width - 4) as $line) {
|
foreach ($this->splitStringByWidth($line, $width - 4) as $line) {
|
||||||
// pre-format lines to get the right string length
|
// pre-format lines to get the right string length
|
||||||
$lineLength = Helper::strlen($line) + 4;
|
$lineLength = Helper::strlen($line) + 4;
|
||||||
@ -1133,9 +1133,8 @@ class Application
|
|||||||
$lines[] = str_pad($line, $width);
|
$lines[] = str_pad($line, $width);
|
||||||
$line = $char;
|
$line = $char;
|
||||||
}
|
}
|
||||||
if ('' !== $line) {
|
|
||||||
$lines[] = count($lines) ? str_pad($line, $width) : $line;
|
$lines[] = count($lines) ? str_pad($line, $width) : $line;
|
||||||
}
|
|
||||||
|
|
||||||
mb_convert_variables($encoding, 'utf8', $lines);
|
mb_convert_variables($encoding, 'utf8', $lines);
|
||||||
|
|
||||||
|
@ -608,6 +608,22 @@ class ApplicationTest extends TestCase
|
|||||||
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception_escapeslines.txt', $tester->getDisplay(true), '->renderException() escapes lines containing formatting');
|
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception_escapeslines.txt', $tester->getDisplay(true), '->renderException() escapes lines containing formatting');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testRenderExceptionLineBreaks()
|
||||||
|
{
|
||||||
|
$application = $this->getMockBuilder('Symfony\Component\Console\Application')->setMethods(array('getTerminalWidth'))->getMock();
|
||||||
|
$application->setAutoExit(false);
|
||||||
|
$application->expects($this->any())
|
||||||
|
->method('getTerminalWidth')
|
||||||
|
->will($this->returnValue(120));
|
||||||
|
$application->register('foo')->setCode(function () {
|
||||||
|
throw new \InvalidArgumentException("\n\nline 1 with extra spaces \nline 2\n\nline 4\n");
|
||||||
|
});
|
||||||
|
$tester = new ApplicationTester($application);
|
||||||
|
|
||||||
|
$tester->run(array('command' => 'foo'), array('decorated' => false));
|
||||||
|
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception_linebreaks.txt', $tester->getDisplay(true), '->renderException() keep multiple line breaks');
|
||||||
|
}
|
||||||
|
|
||||||
public function testRun()
|
public function testRun()
|
||||||
{
|
{
|
||||||
$application = new Application();
|
$application = new Application();
|
||||||
|
@ -0,0 +1,11 @@
|
|||||||
|
|
||||||
|
|
||||||
|
[InvalidArgumentException]
|
||||||
|
line 1 with extra spaces
|
||||||
|
line 2
|
||||||
|
|
||||||
|
line 4
|
||||||
|
|
||||||
|
|
||||||
|
foo
|
||||||
|
|
Reference in New Issue
Block a user