diff --git a/composer.json b/composer.json index b59a53f..e07d096 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "require-dev": { "adlawson/timezone": "^1.0", "aws/aws-sdk-php": "^2.4.9|^3.0", - "filp/whoops": "^1.0", + "filp/whoops": "^2.0", "mindscape/raygun4php": "^1.0", "mockery/mockery": "^0.9", "phpunit/phpunit": "^4.8.36", diff --git a/composer.lock b/composer.lock index 97d0528..f0c38da 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "16ebdd79c56f429715a2f01f519ac619", + "content-hash": "9aa54f5acc7f62ff6fc6f97ff5b27b65", "packages": [ { "name": "monolog/monolog", @@ -180,16 +180,16 @@ }, { "name": "aws/aws-sdk-php", - "version": "3.61.8", + "version": "3.61.9", "source": { "type": "git", "url": "https://github.com/aws/aws-sdk-php.git", - "reference": "7df3b62d06da6512c752b2fd224a65fc0d8c0cbe" + "reference": "57041356c1bb7fdcaba2e181feec56f854b52e38" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/7df3b62d06da6512c752b2fd224a65fc0d8c0cbe", - "reference": "7df3b62d06da6512c752b2fd224a65fc0d8c0cbe", + "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/57041356c1bb7fdcaba2e181feec56f854b52e38", + "reference": "57041356c1bb7fdcaba2e181feec56f854b52e38", "shasum": "" }, "require": { @@ -256,7 +256,7 @@ "s3", "sdk" ], - "time": "2018-06-15T21:48:00+00:00" + "time": "2018-06-19T20:26:38+00:00" }, { "name": "doctrine/instantiator", @@ -314,37 +314,41 @@ }, { "name": "filp/whoops", - "version": "1.1.10", + "version": "2.2.0", "source": { "type": "git", "url": "https://github.com/filp/whoops.git", - "reference": "72538eeb70bbfb11964412a3d098d109efd012f7" + "reference": "181c4502d8f34db7aed7bfe88d4f87875b8e947a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/filp/whoops/zipball/72538eeb70bbfb11964412a3d098d109efd012f7", - "reference": "72538eeb70bbfb11964412a3d098d109efd012f7", + "url": "https://api.github.com/repos/filp/whoops/zipball/181c4502d8f34db7aed7bfe88d4f87875b8e947a", + "reference": "181c4502d8f34db7aed7bfe88d4f87875b8e947a", "shasum": "" }, "require": { - "php": ">=5.3.0" + "php": "^5.5.9 || ^7.0", + "psr/log": "^1.0.1" }, "require-dev": { - "mockery/mockery": "0.9.*" + "mockery/mockery": "^0.9 || ^1.0", + "phpunit/phpunit": "^4.8.35 || ^5.7", + "symfony/var-dumper": "^2.6 || ^3.0 || ^4.0" + }, + "suggest": { + "symfony/var-dumper": "Pretty print complex values better with var-dumper available", + "whoops/soap": "Formats errors as SOAP responses" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.2-dev" + "dev-master": "2.1-dev" } }, "autoload": { - "psr-0": { - "Whoops": "src/" - }, - "classmap": [ - "src/deprecated" - ] + "psr-4": { + "Whoops\\": "src/Whoops/" + } }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -358,17 +362,16 @@ } ], "description": "php error handling for cool kids", - "homepage": "https://github.com/filp/whoops", + "homepage": "https://filp.github.io/whoops/", "keywords": [ "error", "exception", "handling", "library", - "silex-provider", - "whoops", - "zf2" + "throwable", + "whoops" ], - "time": "2015-06-29T05:42:04+00:00" + "time": "2018-03-03T17:56:25+00:00" }, { "name": "graze/standards", diff --git a/src/Graze/Monolog/Handler/WhoopsHandler.php b/src/Graze/Monolog/Handler/WhoopsHandler.php index 92a7ac0..707be57 100644 --- a/src/Graze/Monolog/Handler/WhoopsHandler.php +++ b/src/Graze/Monolog/Handler/WhoopsHandler.php @@ -52,9 +52,13 @@ 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($context['exception']); - } elseif (isset($context['file']) && $context['line']) { + } elseif (isset($context['file']) && isset($context['line'])) { $this->writeError($record); } } @@ -78,9 +82,9 @@ protected function writeError(array $record) } /** - * @param \Exception $exception + * @param \Exception|\Throwable $exception */ - protected function writeException(\Exception $exception) + protected function writeException($exception) { $whoopsInspector = new WhoopsInspector($exception); diff --git a/tests/unit/src/Graze/Monolog/Handler/WhoopsHandlerTest.php b/tests/unit/src/Graze/Monolog/Handler/WhoopsHandlerTest.php index e86313d..f4a74ba 100644 --- a/tests/unit/src/Graze/Monolog/Handler/WhoopsHandlerTest.php +++ b/tests/unit/src/Graze/Monolog/Handler/WhoopsHandlerTest.php @@ -1,4 +1,5 @@ markTestSkipped('filp/whoops not installed'); } - + $this->handlerWhoops = m::mock('Whoops\Handler\HandlerInterface'); } @@ -28,62 +29,111 @@ public function testInterface() public function testHandleError() { $record = $this->getRecord(300, 'test', ['file' => 'bar', 'line' => 1]); - - $formatter = m::mock('Monolog\\Formatter\\FormatterInterface'); - $handlerMonolog = new WhoopsHandler($this->handlerWhoops); - + $this->handlerWhoops ->shouldReceive('setInspector') ->once() ->with(m::type('Whoops\Exception\Inspector')); - + $this->handlerWhoops ->shouldReceive('setRun') ->once() ->with(m::type('Whoops\Run')); - + $this->handlerWhoops ->shouldReceive('setException') ->once() ->with(m::type('Whoops\Exception\ErrorException')); - + $this->handlerWhoops ->shouldReceive('handle') ->once(); - + $handlerMonolog->handle($record); } public function testHandleException() { $exception = new \Whoops\Exception\ErrorException('foo'); - $record = $this->getRecord(300, 'foo', ['exception' => $exception]); - - $formatter = m::mock('Monolog\\Formatter\\FormatterInterface'); - $handlerMonolog = new WhoopsHandler($this->handlerWhoops); - + + $this->handlerWhoops + ->shouldReceive('setInspector') + ->once() + ->with(m::type('Whoops\Exception\Inspector')); + + $this->handlerWhoops + ->shouldReceive('setRun') + ->once() + ->with(m::type('Whoops\Run')); + + $this->handlerWhoops + ->shouldReceive('setException') + ->once() + ->with($exception); + + $this->handlerWhoops + ->shouldReceive('handle') + ->once(); + + $handlerMonolog->handle($record); + } + + /** + * @requires PHP 7 + */ + public function testHandleThrowable() + { + $exception = new \TypeError('foo'); + $record = $this->getRecord(300, 'foo', ['exception' => $exception]); + $handlerMonolog = new WhoopsHandler($this->handlerWhoops); + $this->handlerWhoops ->shouldReceive('setInspector') ->once() ->with(m::type('Whoops\Exception\Inspector')); - + $this->handlerWhoops ->shouldReceive('setRun') ->once() ->with(m::type('Whoops\Run')); - + $this->handlerWhoops ->shouldReceive('setException') ->once() ->with($exception); - + $this->handlerWhoops ->shouldReceive('handle') ->once(); - + $handlerMonolog->handle($record); } + + /** + * @dataProvider nonTriggeringData + * + * @param array $context + */ + public function testContextWithNotEnoughInformationDoesNotTrigger(array $context) + { + $record = $this->getRecord(300, 'test', $context); + $handlerMonolog = new WhoopsHandler($this->handlerWhoops); + $handlerMonolog->handle($record); + } + + /** + * @return array + */ + public function nonTriggeringData() + { + return [ + [['file' => 'file']], + [['line' => 1]], + [[]], + [['other' => 5]], + ]; + } }