Skip to content

Commit

Permalink
Fixed exit code for exceptions with error code 0
Browse files Browse the repository at this point in the history
  • Loading branch information
Stelian authored and fabpot committed Jun 4, 2013
1 parent e029409 commit bbfde62
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Symfony/Component/Console/Application.php
Expand Up @@ -115,7 +115,7 @@ public function run(InputInterface $input = null, OutputInterface $output = null
}
$statusCode = $e->getCode();

$statusCode = $statusCode ? (is_numeric($statusCode) ? (int) $statusCode : 1) : 0;
$statusCode = is_numeric($statusCode) && $statusCode ? (int) $statusCode : 1;
}

if ($this->autoExit) {
Expand Down
15 changes: 15 additions & 0 deletions src/Symfony/Component/Console/Tests/ApplicationTest.php
Expand Up @@ -516,6 +516,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
Expand Down

0 comments on commit bbfde62

Please sign in to comment.