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

Skip to content

Commit 899fa79

Browse files
keradusfabpot
authored andcommitted
[Console] fixed PHP7 Errors when not using Dispatcher
1 parent 5f4d8e9 commit 899fa79

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/Symfony/Component/Console/Application.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,13 @@ protected function doRunCommand(Command $command, InputInterface $input, OutputI
843843
}
844844

845845
if (null === $this->dispatcher) {
846-
return $command->run($input, $output);
846+
try {
847+
return $command->run($input, $output);
848+
} catch (\Exception $e) {
849+
throw $e;
850+
} catch (\Throwable $e) {
851+
throw new FatalThrowableError($e);
852+
}
847853
}
848854

849855
$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