Fixed exit code for exceptions with error code 0

This commit is contained in:
Stelian 2013-06-03 15:33:17 +02:00 committed by Fabien Potencier
parent e029409fc8
commit bbfde62d7c
2 changed files with 16 additions and 1 deletions

View File

@ -115,7 +115,7 @@ class Application
}
$statusCode = $e->getCode();
$statusCode = $statusCode ? (is_numeric($statusCode) ? (int) $statusCode : 1) : 0;
$statusCode = is_numeric($statusCode) && $statusCode ? (int) $statusCode : 1;
}
if ($this->autoExit) {

View File

@ -516,6 +516,21 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
$this->assertSame(4, $exitCode, '->run() returns integer exit code extracted from raised exception');
}
public function testRunReturnsExitCodeOneForExceptionCodeZero()
{
$exception = new \Exception('', 0);
$application = $this->getMock('Symfony\Component\Console\Application', array('doRun'));
$application->setAutoExit(false);
$application->expects($this->once())
->method('doRun')
->will($this->throwException($exception));
$exitCode = $application->run(new ArrayInput(array()), new NullOutput());
$this->assertSame(1, $exitCode, '->run() returns exit code 1 when exception code is 0');
}
/**
* @expectedException \LogicException
* @dataProvider getAddingAlreadySetDefinitionElementData