Example #1
0
 /**
  * @covers ::handleUncaughtException
  */
 public function testHandleUncaughtException()
 {
     $this->expectOutputRegex("~There was an exception.~");
     $exception = new TestingException("There was an exception.", 42);
     $logger = new TestErrorLogger();
     $this->handler->setLogger($logger);
     $this->handler->handle();
     $this->assertTrue($this->handler->handleUncaughtException($exception));
     $this->assertEquals(LogLevel::ERROR, $logger->level);
     $this->assertRegExp('~^Uncaught Exception TestingException\\[42\\]: "There was an exception\\." in file~', $logger->message);
     // Once an exception has been handled, we do not handle them any longer.
     $this->assertFalse($this->handler->handle());
     $this->assertFalse($this->handler->isHandling());
 }
Example #2
0
 /**
  * The default error callback
  * 
  * This is the default error callback. It displays a web page with error information.
  * This should not be used in production. Ever.
  *
  * @param  ErrorHandler $handler The object that handled the error
  * @return mixed
  */
 public function defaultCallback($handler)
 {
     $exception = $handler->getLastError();
     if (php_sapi_name() != "cli") {
         $message = htmlspecialchars($exception->getMessage());
         $trace = nl2br(htmlspecialchars($exception->getTraceAsString()));
         echo "<!DOCTYPE html><html><head><title>Error</title></head><body>", "<h1>{$message}</h1><p>{$trace}</p></body><html>";
     } else {
         echo $exception->getMessage() . PHP_EOL, "-----------" . PHP_EOL, $exception->getTraceAsString() . PHP_EOL;
     }
 }