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 f9bceb8

Browse filesBrowse files
committed
bug #20736 [Console] fixed PHP7 Errors when not using Dispatcher (keradus)
This PR was squashed before being merged into the 2.7 branch (closes #20736). Discussion ---------- [Console] fixed PHP7 Errors when not using Dispatcher | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #17257, #20110, #20111 | License | MIT | Doc PR | n/a Original fix, #19813, works only when there is event dispatcher available. This PR fix the issue also for scenario without event dispatcher. Closes #20110 issue and #20111 PR connected to it. Closing #17257 , as everywhere the error is converted to exception and it should be handled Commits ------- 899fa79 [Console] fixed PHP7 Errors when not using Dispatcher
2 parents e70dc64 + 899fa79 commit f9bceb8
Copy full SHA for f9bceb8

File tree

2 files changed

+25
-1
lines changed
Filter options

2 files changed

+25
-1
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Console/Application.php
+7-1Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,13 @@ protected function doRunCommand(Command $command, InputInterface $input, OutputI
843843
}
844844

845845
if (null === $this->dispatcher) {
846-
return $command->run($input, $output);
846+
try {
847+
return $command->run($input, $output);
848+
} catch (\Exception $e) {
849+
throw $e;
850+
} catch (\Throwable $e) {
851+
throw new FatalThrowableError($e);
852+
}
847853
}
848854

849855
$event = new ConsoleCommandEvent($command, $input, $output);

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

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

954+
public function testRunWithError()
955+
{
956+
$this->setExpectedException('Exception', 'dymerr');
957+
958+
$application = new Application();
959+
$application->setAutoExit(false);
960+
$application->setCatchExceptions(false);
961+
962+
$application->register('dym')->setCode(function (InputInterface $input, OutputInterface $output) {
963+
$output->write('dym.');
964+
965+
throw new \Error('dymerr');
966+
});
967+
968+
$tester = new ApplicationTester($application);
969+
$tester->run(array('command' => 'dym'));
970+
}
971+
954972
/**
955973
* @expectedException \LogicException
956974
* @expectedExceptionMessage caught

0 commit comments

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