[Console] Give errors back to error handlers if not handled by console.error listeners

This commit is contained in:
Robin Chalas 2017-04-03 23:35:40 +02:00
parent 4a5f22bc1e
commit 5a5bf54d37
2 changed files with 27 additions and 0 deletions

View File

@ -138,6 +138,9 @@ class Application
$e = null;
$exitCode = 0;
} else {
if (!$e instanceof \Exception) {
throw $e;
}
$exitCode = $e->getCode();
}

View File

@ -1117,6 +1117,30 @@ class ApplicationTest extends TestCase
$tester->run(array('command' => 'dym'));
}
/**
* @requires PHP 7
*/
public function testErrorIsRethrownIfNotHandledByConsoleErrorEvent()
{
$application = new Application();
$application->setAutoExit(false);
$application->setDispatcher(new EventDispatcher());
$application->register('dym')->setCode(function (InputInterface $input, OutputInterface $output) {
new \UnknownClass();
});
$tester = new ApplicationTester($application);
try {
$tester->run(array('command' => 'dym'));
$this->fail('->run() should rethrow PHP errors if not handled via ConsoleErrorEvent.');
} catch (\Throwable $e) {
$this->assertInstanceOf('Error', $e);
$this->assertSame($e->getMessage(), 'Class \'UnknownClass\' not found');
}
}
/**
* @expectedException \LogicException
* @expectedExceptionMessage error