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
This commit is contained in:
commit
f9bceb832f
|
@ -843,7 +843,13 @@ class Application
|
|||
}
|
||||
|
||||
if (null === $this->dispatcher) {
|
||||
return $command->run($input, $output);
|
||||
try {
|
||||
return $command->run($input, $output);
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
} catch (\Throwable $e) {
|
||||
throw new FatalThrowableError($e);
|
||||
}
|
||||
}
|
||||
|
||||
$event = new ConsoleCommandEvent($command, $input, $output);
|
||||
|
|
|
@ -951,6 +951,24 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertContains('before.foo.caught.after.', $tester->getDisplay());
|
||||
}
|
||||
|
||||
public function testRunWithError()
|
||||
{
|
||||
$this->setExpectedException('Exception', 'dymerr');
|
||||
|
||||
$application = new Application();
|
||||
$application->setAutoExit(false);
|
||||
$application->setCatchExceptions(false);
|
||||
|
||||
$application->register('dym')->setCode(function (InputInterface $input, OutputInterface $output) {
|
||||
$output->write('dym.');
|
||||
|
||||
throw new \Error('dymerr');
|
||||
});
|
||||
|
||||
$tester = new ApplicationTester($application);
|
||||
$tester->run(array('command' => 'dym'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \LogicException
|
||||
* @expectedExceptionMessage caught
|
||||
|
|
Reference in New Issue