Fix errors not rethrown even if not handled by console.error listeners

This commit is contained in:
Robin Chalas 2017-05-11 15:58:12 +02:00
parent 2f1c28bbbc
commit 75f098fcb8
2 changed files with 24 additions and 1 deletions

View File

@ -129,7 +129,7 @@ class Application
}
if (null !== $e) {
if (!$this->catchExceptions) {
if (!$this->catchExceptions || !$x instanceof \Exception) {
throw $x;
}

View File

@ -1170,6 +1170,29 @@ class ApplicationTest extends TestCase
return $dispatcher;
}
/**
* @requires PHP 7
*/
public function testErrorIsRethrownIfNotHandledByConsoleErrorEventWithCatchingEnabled()
{
$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 (\Error $e) {
$this->assertSame($e->getMessage(), 'Class \'UnknownClass\' not found');
}
}
}
class CustomApplication extends Application