diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php index 0d66598204..3989b0ec83 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -899,13 +899,15 @@ class Application try { $exitCode = $command->run($input, $output); } catch (\Exception $e) { + $event = new ConsoleExceptionEvent($command, $input, $output, $e, $e->getCode()); + $this->dispatcher->dispatch(ConsoleEvents::EXCEPTION, $event); + + $e = $event->getException(); + $event = new ConsoleTerminateEvent($command, $input, $output, $e->getCode()); $this->dispatcher->dispatch(ConsoleEvents::TERMINATE, $event); - $event = new ConsoleExceptionEvent($command, $input, $output, $e, $event->getExitCode()); - $this->dispatcher->dispatch(ConsoleEvents::EXCEPTION, $event); - - throw $event->getException(); + throw $e; } $event = new ConsoleTerminateEvent($command, $input, $output, $exitCode); diff --git a/src/Symfony/Component/Console/Tests/ApplicationTest.php b/src/Symfony/Component/Console/Tests/ApplicationTest.php index c7798bf2c5..713f864715 100644 --- a/src/Symfony/Component/Console/Tests/ApplicationTest.php +++ b/src/Symfony/Component/Console/Tests/ApplicationTest.php @@ -799,7 +799,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase $tester = new ApplicationTester($application); $tester->run(array('command' => 'foo')); - $this->assertEquals('before.foo.after.', $tester->getDisplay()); + $this->assertEquals('before.foo.after.'.PHP_EOL, $tester->getDisplay()); } /** @@ -835,7 +835,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase $tester = new ApplicationTester($application); $tester->run(array('command' => 'foo')); - $this->assertContains('before.foo.after.caught.', $tester->getDisplay()); + $this->assertContains('before.foo.caught.after.', $tester->getDisplay()); } protected function getDispatcher() @@ -845,12 +845,12 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase $event->getOutput()->write('before.'); }); $dispatcher->addListener('console.terminate', function (ConsoleTerminateEvent $event) { - $event->getOutput()->write('after.'); + $event->getOutput()->writeln('after.'); $event->setExitCode(128); }); $dispatcher->addListener('console.exception', function (ConsoleExceptionEvent $event) { - $event->getOutput()->writeln('caught.'); + $event->getOutput()->write('caught.'); $event->setException(new \LogicException('caught.', $event->getExitCode(), $event->getException())); });