From 162e71ec84f65f69c278ebb6a89c9b1f8a5c7527 Mon Sep 17 00:00:00 2001 From: Dariusz Ruminski Date: Sat, 3 Dec 2016 12:12:21 +0100 Subject: [PATCH 1/3] [Console] fixed PHP7 Errors when not using Dispatcher --- src/Symfony/Component/Console/Application.php | 10 +++++++++- .../Console/Tests/ApplicationTest.php | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php index b11268ade33bf..76a299e0753d5 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -159,6 +159,8 @@ public function run(InputInterface $input = null, OutputInterface $output = null * @param OutputInterface $output An Output instance * * @return int 0 if everything went fine, or an error code + * + * @throws \Exception propagate the exception from `doRunCommand` */ public function doRun(InputInterface $input, OutputInterface $output) { @@ -843,7 +845,13 @@ protected function doRunCommand(Command $command, InputInterface $input, OutputI } if (null === $this->dispatcher) { - return $command->run($input, $output); + try { + return $command->run($input, $output); + } catch (\Exception $e) { + throw $e; + } catch (\Throwable $e) { + throw new FatalThrowableError($e); + } } $event = new ConsoleCommandEvent($command, $input, $output); diff --git a/src/Symfony/Component/Console/Tests/ApplicationTest.php b/src/Symfony/Component/Console/Tests/ApplicationTest.php index 9d375f6b7b264..2612be9e9eaaa 100644 --- a/src/Symfony/Component/Console/Tests/ApplicationTest.php +++ b/src/Symfony/Component/Console/Tests/ApplicationTest.php @@ -951,6 +951,24 @@ public function testRunDispatchesAllEventsWithException() $this->assertContains('before.foo.caught.after.', $tester->getDisplay()); } + public function testRunWithError() + { + $this->setExpectedException('Exception', 'dymerr'); + + $application = new Application(); + $application->setAutoExit(false); + $application->setCatchExceptions(false); + + $application->register('dym')->setCode(function (InputInterface $input, OutputInterface $output) { + $output->write('dym.'); + + throw new \Error('dymerr'); + }); + + $tester = new ApplicationTester($application); + $tester->run(array('command' => 'dym')); + } + /** * @expectedException \LogicException * @expectedExceptionMessage caught From 5110b3e37be1a74363170d7d76b51be938077cf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dariusz=20Rumi=C5=84ski?= Date: Mon, 5 Dec 2016 11:10:50 +0100 Subject: [PATCH 2/3] Update Application.php --- src/Symfony/Component/Console/Application.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php index 76a299e0753d5..af96fbcefc768 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -160,7 +160,7 @@ public function run(InputInterface $input = null, OutputInterface $output = null * * @return int 0 if everything went fine, or an error code * - * @throws \Exception propagate the exception from `doRunCommand` + * @throws \Exception when the command being run threw an exception */ public function doRun(InputInterface $input, OutputInterface $output) { From 5adbcf2ad30bda3353317bc9861ea538983366b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dariusz=20Rumi=C5=84ski?= Date: Mon, 5 Dec 2016 12:05:58 +0100 Subject: [PATCH 3/3] Update Application.php --- src/Symfony/Component/Console/Application.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php index af96fbcefc768..2aff1b635ba1c 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -159,8 +159,6 @@ public function run(InputInterface $input = null, OutputInterface $output = null * @param OutputInterface $output An Output instance * * @return int 0 if everything went fine, or an error code - * - * @throws \Exception when the command being run threw an exception */ public function doRun(InputInterface $input, OutputInterface $output) {