/** * Sends all the errors collected by the error handler. */ public function sendErrors() { $errors = $this->errorHandler->getErrors(); if (empty($errors)) { return; } $report = $this->reportFactory->createFromErrors($errors); try { $this->client->sendReport($report); } catch (BadResponseException $exception) { $label = 'Error'; $request = $exception->getRequest(); $response = $exception->getResponse(); if ($response->isClientError()) { $label = 'Client error'; } elseif ($response->isServerError()) { $label = 'Server error'; } error_log(sprintf('%s "%s" with status code %i at %s', $label, $response->getReasonPhrase(), $response->getStatusCode(), $request->getUrl())); } catch (\Exception $exception) { error_log($exception->getMessage()); } }
/** * Registers a error handler. * * @param integer $level * * @return ErrorHandler */ private static function registerErrorHandler($level) { return ErrorHandler::register(new ErrorFactory(), $level); }
public function testHandleMultiple() { $that = $this; $errorCheck = function ($exception) use($that) { $that->assertInstanceOf('\\ErrorException', $exception); $that->assertEquals(E_ERROR, $exception->getSeverity()); $that->assertEquals('foo.php', $exception->getFile()); $that->assertEquals(13, $exception->getLine()); $that->assertEquals('bar', $exception->getMessage()); }; $exceptionCheck = function ($exception) use($that) { $that->assertInstanceOf('\\Exception', $exception); $that->assertEquals(__FILE__, $exception->getFile()); $that->assertEquals(__LINE__ + 10, $exception->getLine()); $that->assertEquals('foo', $exception->getMessage()); }; $factory = $this->getErrorFactoryMock(); $factory->expects($this->at(0))->method('createError')->will($this->returnCallback($errorCheck)); $factory->expects($this->at(1))->method('createError')->will($this->returnCallback($exceptionCheck)); $handler = ErrorHandler::register($factory); $handler->handleError(E_ERROR, 'bar', 'foo.php', 13); $handler->handleException(new \Exception('foo')); $this->assertCount(2, $handler->getErrors()); }