Permalink
Browse files

CliTester: uses own error handlers

  • Loading branch information...
dg committed Oct 24, 2018
1 parent 8435694 commit 8ca61440827d812b1fda9e589d408b566f370212
Showing with 30 additions and 1 deletion.
  1. +30 βˆ’1 src/Runner/CliTester.php
@@ -29,7 +29,7 @@ class CliTester
public function run(): ?int
{
Environment::setupColors();
Environment::setupErrors();
$this->setupErrors();
ob_start();
$cmd = $this->loadOptions();
@@ -271,4 +271,33 @@ private function watch(Runner $runner): void
sleep(2);
}
}
private function setupErrors(): void
{
error_reporting(E_ALL);
ini_set('html_errors', '0');
set_error_handler(function (int $severity, string $message, string $file, int $line) {
if (($severity & error_reporting()) === $severity) {
throw new \ErrorException($message, 0, $severity, $file, $line);
}
return false;
});
set_exception_handler(function (\Throwable $e) {
$this->displayException($e);
exit(2);
});
}
private function displayException(\Throwable $e): void
{
echo "\n";
echo Environment::$debugMode
? Dumper::dumpException($e)
: Dumper::color('white/red', 'Error: ' . $e->getMessage());
echo "\n";
}
}

0 comments on commit 8ca6144

Please sign in to comment.