Dispatch console.terminate *after* console.exception

This commit is contained in:
Jordi Boggiano 2015-09-08 10:52:13 +01:00
parent 6430c828f6
commit 7802345824
2 changed files with 10 additions and 8 deletions

View File

@ -899,13 +899,15 @@ class Application
try { try {
$exitCode = $command->run($input, $output); $exitCode = $command->run($input, $output);
} catch (\Exception $e) { } 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()); $event = new ConsoleTerminateEvent($command, $input, $output, $e->getCode());
$this->dispatcher->dispatch(ConsoleEvents::TERMINATE, $event); $this->dispatcher->dispatch(ConsoleEvents::TERMINATE, $event);
$event = new ConsoleExceptionEvent($command, $input, $output, $e, $event->getExitCode()); throw $e;
$this->dispatcher->dispatch(ConsoleEvents::EXCEPTION, $event);
throw $event->getException();
} }
$event = new ConsoleTerminateEvent($command, $input, $output, $exitCode); $event = new ConsoleTerminateEvent($command, $input, $output, $exitCode);

View File

@ -799,7 +799,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
$tester = new ApplicationTester($application); $tester = new ApplicationTester($application);
$tester->run(array('command' => 'foo')); $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 = new ApplicationTester($application);
$tester->run(array('command' => 'foo')); $tester->run(array('command' => 'foo'));
$this->assertContains('before.foo.after.caught.', $tester->getDisplay()); $this->assertContains('before.foo.caught.after.', $tester->getDisplay());
} }
protected function getDispatcher() protected function getDispatcher()
@ -845,12 +845,12 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
$event->getOutput()->write('before.'); $event->getOutput()->write('before.');
}); });
$dispatcher->addListener('console.terminate', function (ConsoleTerminateEvent $event) { $dispatcher->addListener('console.terminate', function (ConsoleTerminateEvent $event) {
$event->getOutput()->write('after.'); $event->getOutput()->writeln('after.');
$event->setExitCode(128); $event->setExitCode(128);
}); });
$dispatcher->addListener('console.exception', function (ConsoleExceptionEvent $event) { $dispatcher->addListener('console.exception', function (ConsoleExceptionEvent $event) {
$event->getOutput()->writeln('caught.'); $event->getOutput()->write('caught.');
$event->setException(new \LogicException('caught.', $event->getExitCode(), $event->getException())); $event->setException(new \LogicException('caught.', $event->getExitCode(), $event->getException()));
}); });