Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bbfde62

Browse files
Stelianfabpot
authored andcommitted
Fixed exit code for exceptions with error code 0
1 parent e029409 commit bbfde62

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/Symfony/Component/Console/Application.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public function run(InputInterface $input = null, OutputInterface $output = null
115115
}
116116
$statusCode = $e->getCode();
117117

118-
$statusCode = $statusCode ? (is_numeric($statusCode) ? (int) $statusCode : 1) : 0;
118+
$statusCode = is_numeric($statusCode) && $statusCode ? (int) $statusCode : 1;
119119
}
120120

121121
if ($this->autoExit) {

src/Symfony/Component/Console/Tests/ApplicationTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,21 @@ public function testRunReturnsIntegerExitCode()
516516
$this->assertSame(4, $exitCode, '->run() returns integer exit code extracted from raised exception');
517517
}
518518

519+
public function testRunReturnsExitCodeOneForExceptionCodeZero()
520+
{
521+
$exception = new \Exception('', 0);
522+
523+
$application = $this->getMock('Symfony\Component\Console\Application', array('doRun'));
524+
$application->setAutoExit(false);
525+
$application->expects($this->once())
526+
->method('doRun')
527+
->will($this->throwException($exception));
528+
529+
$exitCode = $application->run(new ArrayInput(array()), new NullOutput());
530+
531+
$this->assertSame(1, $exitCode, '->run() returns exit code 1 when exception code is 0');
532+
}
533+
519534
/**
520535
* @expectedException \LogicException
521536
* @dataProvider getAddingAlreadySetDefinitionElementData

0 commit comments

Comments
 (0)