Skip to content

Commit

Permalink
Merge pull request #14 from Lead-iD/feature/php7
Browse files Browse the repository at this point in the history
Support Throwable on PHP 7 for Raygun Handler
  • Loading branch information
wpillar committed Apr 6, 2016
2 parents 4973b0a + fa5c0a8 commit 10c85e4
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Graze/Monolog/Handler/RaygunHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,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,
$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 @@ -103,4 +103,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 10c85e4

Please sign in to comment.