Skip to content

Commit

Permalink
CliTester: uses own error handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Oct 24, 2018
1 parent 8435694 commit 8ca6144
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/Runner/CliTester.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class CliTester
public function run(): ?int
{
Environment::setupColors();
Environment::setupErrors();
$this->setupErrors();

ob_start();
$cmd = $this->loadOptions();
Expand Down Expand Up @@ -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.