Skip to content

Commit 8ca6144

Browse files
committed
CliTester: uses own error handlers
1 parent 8435694 commit 8ca6144

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

src/Runner/CliTester.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class CliTester
2929
public function run(): ?int
3030
{
3131
Environment::setupColors();
32-
Environment::setupErrors();
32+
$this->setupErrors();
3333

3434
ob_start();
3535
$cmd = $this->loadOptions();
@@ -271,4 +271,33 @@ private function watch(Runner $runner): void
271271
sleep(2);
272272
}
273273
}
274+
275+
276+
private function setupErrors(): void
277+
{
278+
error_reporting(E_ALL);
279+
ini_set('html_errors', '0');
280+
281+
set_error_handler(function (int $severity, string $message, string $file, int $line) {
282+
if (($severity & error_reporting()) === $severity) {
283+
throw new \ErrorException($message, 0, $severity, $file, $line);
284+
}
285+
return false;
286+
});
287+
288+
set_exception_handler(function (\Throwable $e) {
289+
$this->displayException($e);
290+
exit(2);
291+
});
292+
}
293+
294+
295+
private function displayException(\Throwable $e): void
296+
{
297+
echo "\n";
298+
echo Environment::$debugMode
299+
? Dumper::dumpException($e)
300+
: Dumper::color('white/red', 'Error: ' . $e->getMessage());
301+
echo "\n";
302+
}
274303
}

0 commit comments

Comments
 (0)