From 6c123606aef68b6c3b9a531c7010e0e5bd677acc Mon Sep 17 00:00:00 2001 From: Bishop Bettini Date: Sat, 20 Mar 2021 15:20:27 -0400 Subject: [PATCH 1/4] feat: support rollbar-agent in logging config --- src/AgentHandler.php | 24 ++++++++++++++++++++++++ src/RollbarServiceProvider.php | 6 ++++++ 2 files changed, 30 insertions(+) create mode 100644 src/AgentHandler.php diff --git a/src/AgentHandler.php b/src/AgentHandler.php new file mode 100644 index 0000000..45cddb1 --- /dev/null +++ b/src/AgentHandler.php @@ -0,0 +1,24 @@ + Date: Sat, 20 Mar 2021 23:28:54 -0400 Subject: [PATCH 2/4] feat: ignore PHPUnit cached result It's a by-product of `composer test`, which we don't care to commit. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index fc7ea17..4b53aba 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /vendor composer.lock .DS_Store +.phpunit.result.cache From fe45c3062649aa2082ddc94f481e242bb29e6775 Mon Sep 17 00:00:00 2001 From: Bishop Bettini Date: Sat, 20 Mar 2021 23:33:44 -0400 Subject: [PATCH 3/4] feat: add test coverage --- src/RollbarServiceProvider.php | 3 ++- tests/RollbarTest.php | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/RollbarServiceProvider.php b/src/RollbarServiceProvider.php index caea0a4..a5f3b79 100644 --- a/src/RollbarServiceProvider.php +++ b/src/RollbarServiceProvider.php @@ -45,7 +45,8 @@ public function register() // Convert a request for the Rollbar agent to handle the logs to // the format expected by `Rollbar::init`. // @see https://github.com/rollbar/rollbar-php-laravel/issues/85 - if ($config['handler'] instanceof AgentHandler) { + $handler = Arr::pull($config, 'handler'); + if ($handler instanceof AgentHandler) { $config['handler'] = 'agent'; } Rollbar::init($config, $handleException, $handleError, $handleFatal); diff --git a/tests/RollbarTest.php b/tests/RollbarTest.php index 1551361..08ff2ad 100644 --- a/tests/RollbarTest.php +++ b/tests/RollbarTest.php @@ -4,6 +4,7 @@ use Rollbar\Laravel\RollbarServiceProvider; use Rollbar\Laravel\MonologHandler; +use Rollbar\Laravel\AgentHandler; use Rollbar\RollbarLogger; use Monolog\Logger; use Mockery; @@ -32,6 +33,9 @@ public function testBinding() $handler = $this->app->make(MonologHandler::class); $this->assertInstanceOf(MonologHandler::class, $handler); + + $handler = $this->app->make(AgentHandler::class); + $this->assertInstanceOf(AgentHandler::class, $handler); } public function testIsSingleton() @@ -62,6 +66,21 @@ public function testCustomConfiguration() $this->assertEquals(E_ERROR, $config['included_errno']); } + public function testRollbarAgentConfigurationAdapter() + { + $handler = Mockery::mock(AgentHandler::class); + $this->app->config->set('logging.channels.rollbar.handler', $handler); + + $client = $this->app->make(RollbarLogger::class); + $config = $client->extend([]); + + $this->assertEquals( + 'agent', + $config['handler'], + 'AgentHandler given as Laravel logging config handler should be given as "agent" to Rollbar::init' + ); + } + // public function testAutomaticContext() // { // $this->app->session->put('foo', 'bar'); From ff681d58b07887ce4f6043e0403b4f255eb053d0 Mon Sep 17 00:00:00 2001 From: Bishop Bettini Date: Sun, 21 Mar 2021 00:54:12 -0400 Subject: [PATCH 4/4] refac: adjust from theoretical to actual Previous commits had been theoretical. Bounced it against a L8 install and adjusted behavior. --- src/RollbarServiceProvider.php | 4 ++-- tests/RollbarTest.php | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/RollbarServiceProvider.php b/src/RollbarServiceProvider.php index a5f3b79..7b79415 100644 --- a/src/RollbarServiceProvider.php +++ b/src/RollbarServiceProvider.php @@ -45,8 +45,8 @@ public function register() // Convert a request for the Rollbar agent to handle the logs to // the format expected by `Rollbar::init`. // @see https://github.com/rollbar/rollbar-php-laravel/issues/85 - $handler = Arr::pull($config, 'handler'); - if ($handler instanceof AgentHandler) { + $handler = Arr::get($config, 'handler'); + if ($handler === AgentHandler::class) { $config['handler'] = 'agent'; } Rollbar::init($config, $handleException, $handleError, $handleFatal); diff --git a/tests/RollbarTest.php b/tests/RollbarTest.php index 08ff2ad..a893603 100644 --- a/tests/RollbarTest.php +++ b/tests/RollbarTest.php @@ -68,8 +68,7 @@ public function testCustomConfiguration() public function testRollbarAgentConfigurationAdapter() { - $handler = Mockery::mock(AgentHandler::class); - $this->app->config->set('logging.channels.rollbar.handler', $handler); + $this->app->config->set('logging.channels.rollbar.handler', AgentHandler::class); $client = $this->app->make(RollbarLogger::class); $config = $client->extend([]);