[Console] Give errors back to error handlers if not handled by console.error listeners
This commit is contained in:
parent
4a5f22bc1e
commit
5a5bf54d37
@ -138,6 +138,9 @@ class Application
|
||||
$e = null;
|
||||
$exitCode = 0;
|
||||
} else {
|
||||
if (!$e instanceof \Exception) {
|
||||
throw $e;
|
||||
}
|
||||
$exitCode = $e->getCode();
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user