Skip to content

Commit

Permalink
[Console] fixed PHP7 Errors when not using Dispatcher
Browse files Browse the repository at this point in the history
  • Loading branch information
keradus committed Dec 3, 2016
1 parent 5f4d8e9 commit 9612935
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Symfony/Component/Console/Application.php
Expand Up @@ -159,6 +159,8 @@ public function run(InputInterface $input = null, OutputInterface $output = null
* @param OutputInterface $output An Output instance
*
* @return int 0 if everything went fine, or an error code
*
* @throws \Exception propagate the exception from `doRunCommand`
*/
public function doRun(InputInterface $input, OutputInterface $output)
{
Expand Down Expand Up @@ -843,7 +845,14 @@ protected function doRunCommand(Command $command, InputInterface $input, OutputI
}

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);
Expand Down
19 changes: 19 additions & 0 deletions src/Symfony/Component/Console/Tests/ApplicationTest.php
Expand Up @@ -951,6 +951,25 @@ public function testRunDispatchesAllEventsWithException()
$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'));
$this->assertContains('before.dym.caught.after.', $tester->getDisplay(), 'The PHP Error did not dispached events');
}

/**
* @expectedException \LogicException
* @expectedExceptionMessage caught
Expand Down

0 comments on commit 9612935

Please sign in to comment.