/** * Registers Honeybadger as the global error and exception handler. Any * uncaught exceptions and errors will be sent to Honeybadger by default. * * @return void */ public static function handle_errors() { Error::register_handler(); Exception::register_handler(); }
public function test_should_format_as_array_with_correct_layout() { $exception = new \Exception('Something broke!'); $raw_backtrace = $exception->getTrace(); $raw_backtrace[0]['file'] = path_to_fixture('MyClass.php'); $raw_backtrace[0]['line'] = 1; $backtrace = Backtrace::parse($raw_backtrace); $data = array('backtrace' => $raw_backtrace, 'error_class' => 'Exception', 'error_message' => 'Exception [ 0 ]: Something broke!', 'url' => 'https://example.com/orders', 'component' => 'Orders', 'action' => 'create', 'params' => array('line_item_ids' => array(123, 456, 789)), 'session' => array('user_id' => 123), 'cgi_data' => array('HTTP_HOST' => 'example.com', 'REQUEST_METHOD' => 'POST'), 'context' => array('user' => array('name' => 'Joe Blow')), 'project_root' => '/var/www/application', 'environment_name' => 'production'); $notice = $this->build_notice($data); $this->assertEquals(array('notifier' => array('name' => Honeybadger::NOTIFIER_NAME, 'url' => Honeybadger::NOTIFIER_URL, 'version' => Honeybadger::VERSION, 'language' => 'php'), 'error' => array('class' => $data['error_class'], 'message' => $data['error_message'], 'backtrace' => $backtrace->as_array(), 'source' => $backtrace->lines[0]->source), 'request' => array('url' => $data['url'], 'component' => $data['component'], 'action' => $data['action'], 'params' => $data['params'], 'session' => $data['session'], 'cgi_data' => $data['cgi_data'], 'context' => $data['context']), 'server' => array('project_root' => $data['project_root'], 'environment_name' => $data['environment_name'], 'hostname' => gethostname())), $notice->as_array()); }