Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b56c5de

Browse filesBrowse files
author
Hugo Fonseca
committed
[Console] fixed PHP7 Errors are now handled and converted to Exceptions
1 parent 09e4e49 commit b56c5de
Copy full SHA for b56c5de

File tree

Expand file treeCollapse file tree

2 files changed

+47
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+47
-0
lines changed

‎src/Symfony/Component/Console/Application.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Application.php
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
use Symfony\Component\Console\Event\ConsoleCommandEvent;
3939
use Symfony\Component\Console\Event\ConsoleExceptionEvent;
4040
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
41+
use Symfony\Component\Debug\Exception\FatalThrowableError;
4142
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
4243

4344
/**
@@ -859,6 +860,18 @@ protected function doRunCommand(Command $command, InputInterface $input, OutputI
859860
$event = new ConsoleTerminateEvent($command, $input, $output, $e->getCode());
860861
$this->dispatcher->dispatch(ConsoleEvents::TERMINATE, $event);
861862

863+
throw $e;
864+
} catch (\Throwable $e) {
865+
$e = new FatalThrowableError($e);
866+
867+
$event = new ConsoleExceptionEvent($command, $input, $output, $e, $e->getCode());
868+
$this->dispatcher->dispatch(ConsoleEvents::EXCEPTION, $event);
869+
870+
$e = $event->getException();
871+
872+
$event = new ConsoleTerminateEvent($command, $input, $output, $e->getCode());
873+
$this->dispatcher->dispatch(ConsoleEvents::TERMINATE, $event);
874+
862875
throw $e;
863876
}
864877
} else {

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Tests/ApplicationTest.php
+34Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,40 @@ public function testRunDispatchesAllEventsWithException()
949949
$this->assertContains('before.foo.caught.after.', $tester->getDisplay());
950950
}
951951

952+
public function testRunDispatchesAllEventsWithError()
953+
{
954+
$application = new Application();
955+
$application->setDispatcher($this->getDispatcher());
956+
$application->setAutoExit(false);
957+
958+
$application->register('dym')->setCode(function (InputInterface $input, OutputInterface $output) {
959+
$output->write('dym.');
960+
961+
throw new \Error('dymerr');
962+
});
963+
964+
$tester = new ApplicationTester($application);
965+
$tester->run(array('command' => 'dym'));
966+
$this->assertContains('before.dym.caught.after.', $tester->getDisplay(), 'The PHP Error did not dispached events');
967+
}
968+
969+
public function testRunWithErrorFailingStatusCode()
970+
{
971+
$application = new Application();
972+
$application->setDispatcher($this->getDispatcher());
973+
$application->setAutoExit(false);
974+
975+
$application->register('dus')->setCode(function (InputInterface $input, OutputInterface $output) {
976+
$output->write('dus.');
977+
978+
throw new \Error('duserr');
979+
});
980+
981+
$tester = new ApplicationTester($application);
982+
$tester->run(array('command' => 'dus'));
983+
$this->assertSame(1, $tester->getStatusCode(), 'Status code should be 1');
984+
}
985+
952986
public function testRunWithDispatcherSkippingCommand()
953987
{
954988
$application = new Application();

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.