public function test_parse_returns_backtrace_containing_parsed_lines() { $unparsed_lines = array(array('file' => 'hello.php', 'line' => 1, 'function' => 'world'), array('file' => 'world.php', 'line' => 2, 'function' => 'hello')); $backtrace = Backtrace::parse($unparsed_lines); $expected_lines = array(new Line('hello.php', 1, 'world'), new Line('world.php', 2, 'hello')); $this->assertEquals($expected_lines, $backtrace->lines); }
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(); }
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()); }