diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php index 0ab3c3e0e3..dbb21dad0e 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -138,6 +138,9 @@ class Application $e = null; $exitCode = 0; } else { + if (!$e instanceof \Exception) { + throw $e; + } $exitCode = $e->getCode(); } diff --git a/src/Symfony/Component/Console/Tests/ApplicationTest.php b/src/Symfony/Component/Console/Tests/ApplicationTest.php index 314165a195..2656d4001c 100644 --- a/src/Symfony/Component/Console/Tests/ApplicationTest.php +++ b/src/Symfony/Component/Console/Tests/ApplicationTest.php @@ -1117,6 +1117,30 @@ class ApplicationTest extends TestCase $tester->run(array('command' => 'dym')); } + /** + * @requires PHP 7 + */ + public function testErrorIsRethrownIfNotHandledByConsoleErrorEvent() + { + $application = new Application(); + $application->setAutoExit(false); + $application->setDispatcher(new EventDispatcher()); + + $application->register('dym')->setCode(function (InputInterface $input, OutputInterface $output) { + new \UnknownClass(); + }); + + $tester = new ApplicationTester($application); + + try { + $tester->run(array('command' => 'dym')); + $this->fail('->run() should rethrow PHP errors if not handled via ConsoleErrorEvent.'); + } catch (\Throwable $e) { + $this->assertInstanceOf('Error', $e); + $this->assertSame($e->getMessage(), 'Class \'UnknownClass\' not found'); + } + } + /** * @expectedException \LogicException * @expectedExceptionMessage error