diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php index 81bc1bf104..ad6b85368f 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -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) { diff --git a/src/Symfony/Component/Console/Tests/ApplicationTest.php b/src/Symfony/Component/Console/Tests/ApplicationTest.php index 8f5bce956c..6a51742f62 100644 --- a/src/Symfony/Component/Console/Tests/ApplicationTest.php +++ b/src/Symfony/Component/Console/Tests/ApplicationTest.php @@ -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