8000 [Console] fixed PHP7 Errors are now handled in Application::run and a… · symfony/symfony@779ccc6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 779ccc6

Browse files
committed
[Console] fixed PHP7 Errors are now handled in Application::run and a proper status code is returned
1 parent cf9f541 commit 779ccc6

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/Symfony/Component/Console/Application.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,15 @@ public function run(InputInterface $input = null, OutputInterface $output = null
116116
$this->configureIO($input, $output);
117117

118118
try {
119+
$e = null;
119120
$exitCode = $this->doRun($input, $output);
120-
} catch (\Exception $e) {
121+
} catch (\Exception $x) {
122+
$e = $x;
123+
} catch (\Throwable $x) {
124+
$e = new FatalThrowableError($x);
125+
}
126+
127+
if (null !== $e) {
121128
if (!$this->catchExceptions) {
122129
throw $e;
123130
}

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,24 @@ public function testRunWithError()
969969
$tester->run(array('command' => 'dym'));
970970
}
971971

972+
public function testRunWithErrorCatchExceptionsFailingStatusCode()
973+
{
974+
$application = new Application();
975+
$application->setDispatcher(new EventDispatcher());
976+
$application->setCatchExceptions(true);
977+
$application->setAutoExit(false);
978+
979+
$application->register('dym')->setCode(function (InputInterface $input, OutputInterface $output) {
980+
$output->write('dym.');
981+
982+
throw new \Error('dymerr');
983+
});
984+
985+
$tester = new ApplicationTester($application);
986+
$tester->run(array('command' => 'dym'));
987+
$this->assertSame(1, $tester->getStatusCode(), 'Status code should be 1');
988+
}
989+
972990
/**
973991
* @expectedException \LogicException
974992
* @expectedExceptionMessage caught

0 commit comments

Comments
 (0)
0