Dispatch console.terminate *after* console.exception
This commit is contained in:
parent
6430c828f6
commit
7802345824
@ -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);
|
||||
|
@ -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()));
|
||||
});
|
||||
|
Reference in New Issue
Block a user