Skip to content

Commit 7802345

Browse files
committed
Dispatch console.terminate *after* console.exception
1 parent 6430c82 commit 7802345

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/Symfony/Component/Console/Application.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -899,13 +899,15 @@ protected function doRunCommand(Command $command, InputInterface $input, OutputI
899899
try {
900900
$exitCode = $command->run($input, $output);
901901
} catch (\Exception $e) {
902+
$event = new ConsoleExceptionEvent($command, $input, $output, $e, $e->getCode());
903+
$this->dispatcher->dispatch(ConsoleEvents::EXCEPTION, $event);
904+
905+
$e = $event->getException();
906+
902907
$event = new ConsoleTerminateEvent($command, $input, $output, $e->getCode());
903908
$this->dispatcher->dispatch(ConsoleEvents::TERMINATE, $event);
904909

905-
$event = new ConsoleExceptionEvent($command, $input, $output, $e, $event->getExitCode());
906-
$this->dispatcher->dispatch(ConsoleEvents::EXCEPTION, $event);
907-
908-
throw $event->getException();
910+
throw $e;
909911
}
910912

911913
$event = new ConsoleTerminateEvent($command, $input, $output, $exitCode);

src/Symfony/Component/Console/Tests/ApplicationTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ public function testRunWithDispatcher()
799799

800800
$tester = new ApplicationTester($application);
801801
$tester->run(array('command' => 'foo'));
802-
$this->assertEquals('before.foo.after.', $tester->getDisplay());
802+
$this->assertEquals('before.foo.after.'.PHP_EOL, $tester->getDisplay());
803803
}
804804

805805
/**
@@ -835,7 +835,7 @@ public function testRunDispatchesAllEventsWithException()
835835

836836
$tester = new ApplicationTester($application);
837837
$tester->run(array('command' => 'foo'));
838-
$this->assertContains('before.foo.after.caught.', $tester->getDisplay());
838+
$this->assertContains('before.foo.caught.after.', $tester->getDisplay());
839839
}
840840

841841
protected function getDispatcher()
@@ -845,12 +845,12 @@ protected function getDispatcher()
845845
$event->getOutput()->write('before.');
846846
});
847847
$dispatcher->addListener('console.terminate', function (ConsoleTerminateEvent $event) {
848-
$event->getOutput()->write('after.');
848+
$event->getOutput()->writeln('after.');
849849

850850
$event->setExitCode(128);
851851
});
852852
$dispatcher->addListener('console.exception', function (ConsoleExceptionEvent $event) {
853-
$event->getOutput()->writeln('caught.');
853+
$event->getOutput()->write('caught.');
854854

855855
$event->setException(new \LogicException('caught.', $event->getExitCode(), $event->getException()));
856856
});

0 commit comments

Comments
 (0)