From abb113fae897902fcd997cfa36e580718d76c50f Mon Sep 17 00:00:00 2001 From: Stelian Date: Mon, 3 Jun 2013 15:33:17 +0200 Subject: [PATCH 1/2] Fixed exit code for exceptions with error code 0 --- src/Symfony/Component/Console/Application.php | 2 +- .../Component/Console/Tests/ApplicationTest.php | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php index 8ffdb294bfb68..845c841244385 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -116,7 +116,7 @@ public function run(InputInterface $input = null, OutputInterface $output = null } $statusCode = $e->getCode(); - $statusCode = $statusCode ? (is_numeric($statusCode) ? (int) $statusCode : 1) : 0; + $statusCode = $statusCode ? (is_numeric($statusCode) ? (int) $statusCode : 1) : 1; } if ($this->autoExit) { diff --git a/src/Symfony/Component/Console/Tests/ApplicationTest.php b/src/Symfony/Component/Console/Tests/ApplicationTest.php index 4511e90c9e9dd..7ab65a23816e5 100644 --- a/src/Symfony/Component/Console/Tests/ApplicationTest.php +++ b/src/Symfony/Component/Console/Tests/ApplicationTest.php @@ -529,6 +529,21 @@ public function testRunReturnsIntegerExitCode() $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 From 922aff4ad9c4c8572130119cac1cd127237cf415 Mon Sep 17 00:00:00 2001 From: Stelian Date: Mon, 3 Jun 2013 16:23:42 +0200 Subject: [PATCH 2/2] Refactored the statusCode ternary operator --- src/Symfony/Component/Console/Application.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php index 845c841244385..14d0fc0a1bae4 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -116,7 +116,7 @@ public function run(InputInterface $input = null, OutputInterface $output = null } $statusCode = $e->getCode(); - $statusCode = $statusCode ? (is_numeric($statusCode) ? (int) $statusCode : 1) : 1; + $statusCode = is_numeric($statusCode) && $statusCode ? (int) $statusCode : 1; } if ($this->autoExit) {