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

Skip to content

Commit 28a9001

Browse files
committed
merged branch Stelian/2.2 (PR #8183)
This PR was submitted for the 2.2 branch but it was merged into the 2.1 branch instead (closes #8183). Discussion ---------- Fixed exit code for exceptions with error code 0 Covers #8180 Commits ------- 48e77f8 Fixed exit code for exceptions with error code 0
2 parents e029409 + bbfde62 commit 28a9001

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)