|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Sentry\Laravel\Tests\Sentry\Laravel; |
| 4 | + |
| 5 | +use Illuminate\Log\LogManager; |
| 6 | +use Monolog\Handler\FingersCrossedHandler; |
| 7 | +use Sentry\Laravel\LogChannel; |
| 8 | +use Sentry\Laravel\SentryHandler; |
| 9 | +use Sentry\Laravel\Tests\SentryLaravelTestCase; |
| 10 | + |
| 11 | +class LogChannelTest extends SentryLaravelTestCase |
| 12 | +{ |
| 13 | + public function test_creating_handler_without_action_level_config() |
| 14 | + { |
| 15 | + $this->skipIfLogManagerNotAvailable(); |
| 16 | + |
| 17 | + $logChannel = new LogChannel($this->app); |
| 18 | + $logger = $logChannel([]); |
| 19 | + |
| 20 | + $this->assertContainsOnlyInstancesOf(SentryHandler::class, $logger->getHandlers()); |
| 21 | + } |
| 22 | + |
| 23 | + public function test_creating_handler_with_action_level_config() |
| 24 | + { |
| 25 | + $this->skipIfLogManagerNotAvailable(); |
| 26 | + |
| 27 | + $logChannel = new LogChannel($this->app); |
| 28 | + $logger = $logChannel(['action_level' => 'critical']); |
| 29 | + |
| 30 | + $this->assertContainsOnlyInstancesOf(FingersCrossedHandler::class, $logger->getHandlers()); |
| 31 | + |
| 32 | + $currentHandler = current($logger->getHandlers()); |
| 33 | + $this->assertInstanceOf(SentryHandler::class, $currentHandler->getHandler()); |
| 34 | + |
| 35 | + $loggerWithoutActionLevel = $logChannel(['action_level' => null]); |
| 36 | + |
| 37 | + $this->assertContainsOnlyInstancesOf(SentryHandler::class, $loggerWithoutActionLevel->getHandlers()); |
| 38 | + } |
| 39 | + |
| 40 | + private function skipIfLogManagerNotAvailable() |
| 41 | + { |
| 42 | + if (class_exists(LogManager::class)) { |
| 43 | + return; |
| 44 | + } |
| 45 | + |
| 46 | + $this->markTestSkipped('Laravel version <=5.5 does not contain the LogManager required for this functionality.'); |
| 47 | + } |
| 48 | +} |
0 commit comments