Skip to content

Commit

Permalink
Support Throwable on PHP 7 for Raygun Handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Carpenter committed Apr 5, 2016
1 parent e356913 commit 7c49618
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: php

php: [5.3, 5.4, 5.5]
php: [5.3, 5.4, 5.5, 5.6, 7]

before_script:
- php -r "eval('?>'.file_get_contents('https://getcomposer.org/installer'));"
Expand Down
7 changes: 6 additions & 1 deletion src/Graze/Monolog/Handler/RaygunHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ protected function write(array $record)
{
$context = $record['context'];

if (isset($context['exception']) && $context['exception'] instanceof \Exception) {
if (isset($context['exception']) &&
(
$context['exception'] instanceof \Exception ||
(PHP_VERSION_ID > 70000 && $context['exception'] instanceof \Throwable)
)
) {
$this->writeException(
$record['formatted'],
$record['formatted']['tags'],
Expand Down
33 changes: 33 additions & 0 deletions tests/unit/src/Graze/Monolog/Handler/RaygunHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,37 @@ public function testHandleException()

$handler->handle($record);
}

/**
* @requires PHP 7
*/
public function testHandleThrowable()
{
$exception = new \TypeError('foo');
$record = $this->getRecord(300, 'foo', array('exception' => $exception));
$record['context']['tags'] = array('foo');
$formatted = array_merge($record,
array(
'tags' => array('foo'),
'custom_data' => array(),
'timestamp' => null,
)
);

$formatter = m::mock('Monolog\\Formatter\\FormatterInterface');
$handler = new RaygunHandler($this->client);
$handler->setFormatter($formatter);

$formatter
->shouldReceive('format')
->once()
->with($record)
->andReturn($formatted);
$this->client
->shouldReceive('SendException')
->once()
->with($exception, array('foo'), array(), null);

$handler->handle($record);
}
}

0 comments on commit 7c49618

Please sign in to comment.