8000 [Console] Fix errors not rethrown even if not handled by console.error listeners by chalasr · Pull Request #22690 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Console] Fix errors not rethr 8000 own even if not handled by console.error listeners #22690

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Symfony/Component/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public function run(InputInterface $input = null, OutputInterface $output = null
}

if (null !== $e) {
if (!$this->catchExceptions) {
if (!$this->catchExceptions || !$x instanceof \Exception) {
throw $x;
}

Expand Down
23 changes: 23 additions & 0 deletions src/Symfony/Component/Console/Tests/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,29 @@ protected function getDispatcher($skipCommand = false)

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
Expand Down
0