8000 [Console] Give errors back to error handlers if not handled by consol… · symfony/symfony@5a5bf54 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5a5bf54

Browse files
committed
[Console] Give errors back to error handlers if not handled by console.error listeners
1 parent 4a5f22b commit 5a5bf54

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/Symfony/Component/Console/Application.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ public function run(InputInterface $input = null, OutputInterface $output = null
138138
$e = null;
139139
$exitCode = 0;
140140
} else {
141+
if (!$e instanceof \Exception) {
142+
throw $e;
143+
}
141144
$exitCode = $e->getCode();
142145
}
143146

src/Symfony/Component/Console/Tests/ApplicationTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,6 +1117,30 @@ public function testRunWithError()
11171117
$tester->run(array('command' => 'dym'));
11181118
}
11191119

1120+
/**
1121+
* @requires PHP 7
1122+
*/
1123+
public function testErrorIsRethrownIfNotHandledByConsoleErrorEvent()
1124+
{
1125+
$application = new Application();
1126+
$application->setAutoExit(false);
1127+
$application->setDispatcher(new EventDispatcher());
1128+
1129+
$application->register('dym')->setCode(function (InputInterface $input, OutputInterface $output) {
1130+
new \UnknownClass();
1131+
});
1132+
1133+
$tester = new ApplicationTester($application);
1134+
1135+
try {
1136+
$tester->run(array('command' => 'dym'));
1137+
$this->fail('->run() should rethrow PHP errors if not handled via ConsoleErrorEvent.');
1138+
} catch (\Throwable $e) {
1139+
$this->assertInstanceOf(' 5FB1 ;Error', $e);
1140+
$this->assertSame($e->getMessage(), 'Class \'UnknownClass\' not found');
1141+
}
1142+
}
1143+
11201144
/**
11211145
* @expectedException \LogicException
11221146
* @expectedExceptionMessage error

0 commit comments

Comments
 (0)
0