From fa5c0a8ed6110cacbaf64b5e6dd5a9856d2dbc8a Mon Sep 17 00:00:00 2001 From: Ian Carpenter Date: Tue, 5 Apr 2016 16:17:23 -0400 Subject: [PATCH] Support Throwable on PHP 7 for Raygun Handler --- src/Graze/Monolog/Handler/RaygunHandler.php | 7 +++- .../Monolog/Handler/RaygunHandlerTest.php | 33 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/Graze/Monolog/Handler/RaygunHandler.php b/src/Graze/Monolog/Handler/RaygunHandler.php index 06eec59..7af4505 100644 --- a/src/Graze/Monolog/Handler/RaygunHandler.php +++ b/src/Graze/Monolog/Handler/RaygunHandler.php @@ -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['formatted'], $record['formatted']['tags'], diff --git a/tests/unit/src/Graze/Monolog/Handler/RaygunHandlerTest.php b/tests/unit/src/Graze/Monolog/Handler/RaygunHandlerTest.php index 41af50d..26e7330 100644 --- a/tests/unit/src/Graze/Monolog/Handler/RaygunHandlerTest.php +++ b/tests/unit/src/Graze/Monolog/Handler/RaygunHandlerTest.php @@ -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); + } }