Exemplo n.º 1
0
 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());
 }
Exemplo n.º 2
0
 public function __construct(array $args = array())
 {
     // Store self to allow access in callbacks.
     self::$current = $this;
     $this->args = $args;
     $this->cgi_data = Environment::factory(Arr::get($args, 'cgi_data'));
     $this->project_root = Arr::get($args, 'project_root');
     $this->url = Arr::get($args, 'url', $this->cgi_data['url']);
     $this->environment_name = Arr::get($args, 'environment_name');
     $this->notifier_name = Arr::get($args, 'notifier_name');
     $this->notifier_version = Arr::get($args, 'notifier_version');
     $this->notifier_url = Arr::get($args, 'notifier_url');
     $this->ignore = Arr::get($args, 'ignore', array());
     $this->ignore_by_filters = Arr::get($args, 'ignore_by_filters', array());
     $this->backtrace_filters = Arr::get($args, 'backtrace_filters', array());
     $this->params_filters = Arr::get($args, 'params_filters', array());
     if (isset($args['parameters'])) {
         $this->params = $args['parameters'];
     } elseif (isset($args['params'])) {
         $this->params = $args['params'];
     }
     if (isset($args['component'])) {
         $this->component = $args['component'];
     } elseif (isset($args['controller'])) {
         $this->component = $args['controller'];
     } elseif (isset($this->params['controller'])) {
         $this->component = $this->params['controller'];
     }
     if (isset($args['action'])) {
         $this->action = $args['action'];
     } elseif (isset($this->params['action'])) {
         $this->action = $this->params['action'];
     }
     $this->exception = Arr::get($args, 'exception');
     if ($this->exception instanceof \Exception) {
         $backtrace = $this->exception->getTrace();
         if (empty($backtrace)) {
             $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
         }
         $this->error_class = get_class($this->exception);
         $this->error_message = HoneybadgerError::text($this->exception);
     } else {
         if (isset($args['backtrace']) and is_array($args['backtrace'])) {
             $backtrace = $args['backtrace'];
         } else {
             $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
         }
         $this->error_class = Arr::get($args, 'error_class');
         $this->error_message = Arr::get($args, 'error_message', 'Notification');
     }
     $this->backtrace = Backtrace::parse($backtrace, array('filters' => $this->backtrace_filters));
     $this->hostname = gethostname();
     $this->source_extract_radius = Arr::get($args, 'source_extract_radius', 2);
     $this->source_extract = $this->extract_source_from_backtrace();
     $this->send_request_session = Arr::get($args, 'send_request_session', TRUE);
     $this->find_session_data();
     $this->clean_params();
     $this->set_context();
 }
Exemplo n.º 3
0
 public function test_to_json()
 {
     $lines = array(new Line('foo', 11, 'bar'), new Line('baz', 2, 'something'));
     $backtrace = new Backtrace($lines);
     $expected = json_encode(array(array('file' => 'foo', 'number' => 11, 'method' => 'bar'), array('file' => 'baz', 'number' => 2, 'method' => 'something')));
     $this->assertEquals($expected, $backtrace->to_json());
 }