10BC0 [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
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
A45D
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