[Console] fixed PHP7 Errors when not using Dispatcher

This commit is contained in:
Dariusz Ruminski 2016-12-03 12:12:21 +01:00 committed by Fabien Potencier
parent 5f4d8e9441
commit 899fa7936b
2 changed files with 25 additions and 1 deletions

View File

@ -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);

View File

@ -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