10BC0 [Console] fixed PHP7 Errors when not using Dispatcher by keradus · Pull Request #20736 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
[Console] fixed PHP7 Errors when not using Dispatcher
  • Loading branch information
keradus committed Dec 3, 2016
commit 162e71ec84f65f69c278ebb6a89c9b1f8a5c7527
10 changes: 9 additions & 1 deletion src/Symfony/Component/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ public function run(InputInterface $input = null, OutputInterface $output = null
* @param OutputInterface $output An Output instance
*
* @return int 0 if everything went fine, or an error code
*
* @throws \Exception propagate the exception from `doRunCommand`
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is current behaviour, just documenting it as doRunCommand is protected, so it's not part of public interface, which should be documented anyway...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed as it does not bring any useful information (\Exception can be anything, we only document exceptions when we give an explanation about when a specific exception can occur).

*/
public function doRun(InputInterface $input, OutputInterface $output)
{
Expand Down Expand Up @@ -843,7 +845,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
0