From 899fa7936bccb786d0d661c504e06489660101d3 Mon Sep 17 00:00:00 2001 From: Dariusz Ruminski Date: Sat, 3 Dec 2016 12:12:21 +0100 Subject: [PATCH] [Console] fixed PHP7 Errors when not using Dispatcher --- src/Symfony/Component/Console/Application.php | 8 +++++++- .../Console/Tests/ApplicationTest.php | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php index b11268ade3..2aff1b635b 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -843,7 +843,13 @@ class Application } 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 9d375f6b7b..2612be9e9e 100644 --- a/src/Symfony/Component/Console/Tests/ApplicationTest.php +++ b/src/Symfony/Component/Console/Tests/ApplicationTest.php @@ -951,6 +951,24 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase $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