8000 [Console] fixed PHP7 Errors when not using Dispatcher · symfony/symfony@162e71e · GitHub
[go: up one dir, main page]

Skip to content

Commit 162e71e

Browse files
committed
[Console] fixed PHP7 Errors when not using Dispatcher
1 parent 5f4d8e9 commit 162e71e

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/Symfony/Component/Console/Application.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ public function run(InputInterface $input = null, OutputInterface $output = null
159159
* @param OutputInterface $output An Output instance
160160
*
161161
* @return int 0 if everything went fine, or an error code
162+
*
163+
* @throws \Exception propagate the exception from `doRunCommand`
162164
*/
163165
public function doRun(InputInterface $input, OutputInterface $output)
164166
{
@@ -843,7 +845,13 @@ protected function doRunCommand(Command $command, InputInterface $input, OutputI
843845
}
844846

845847
if (null === $this->dispatcher) {
846-
return $command->run($input, $output);
848+
try {
849+
return $command->run($input, $output);
850+
} catch (\Exception $e) {
851+
throw $e;
852+
} catch (\Throwable $e) {
853+
throw new FatalThrowableError($e);
854+
}
847855
}
848856

849857
$event = new ConsoleCommandEvent($command, $input, $output);

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,24 @@ public function testRunDispatchesAllEventsWithException()
951951
$this->assertContains('before.foo.caught.after.', $tester->getDisplay());
952952
}
953953

954+
public function testRunWithError()
955+
{
956+
$this->setExpectedException('Exception', 'dymerr');
957+
958+
$application = new Application();
959+
$application->setAutoExit(false);
960+
$application->setCatchExceptions(false);
961+
962+
$application->register('dym')->setCode(function (InputInterface $input, OutputInterface $output) {
963+
$output->write('dym.');
964+
965+
throw new \Error('dymerr');
966+
});
967+
968+
$tester = new ApplicationTester($application);
969+
$tester->run(array('command' => 'dym'));
970+
}
971+
954972
/**
955973
* @expectedException \LogicException
956974
* @expectedExceptionMessage caught

0 commit comments

Comments
 (0)
0