Skip to content

[Console] fixed PHP7 Errors when not using Dispatcher #20736

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

Closed
wants to merge 3 commits into from
Closed
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
8 changes: 7 additions & 1 deletion src/Symfony/Component/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,13 @@ protected function doRunCommand(Command $command, InputInterface $input, OutputI
}

if (null === $this->dispatcher) {
return $command->run($input, $output);
try {
return $command->run($input, $output);
} catch (\Exception $e) {
throw $e;
} catch (\Throwable $e) {
throw new FatalThrowableError($e);
}
}

$event = new ConsoleCommandEvent($command, $input, $output);
Expand Down
18 changes: 18 additions & 0 deletions src/Symfony/Component/Console/Tests/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,24 @@ public function testRunDispatchesAllEventsWithException()
$this->assertContains('before.foo.caught.after.', $tester->getDisplay());
}

public function testRunWithError()
{
$this->setExpectedException('Exception', 'dymerr');

$application = new Application();
$application->setAutoExit(false);
$application->setCatchExceptions(false);

$application->register('dym')->setCode(function (InputInterface $input, OutputInterface $output) {
$output->write('dym.');

throw new \Error('dymerr');
});

$tester = new ApplicationTester($application);
$tester->run(array('command' => 'dym'));
}

/**
* @expectedException \LogicException
* @expectedExceptionMessage caught
Expand Down