diff --git a/src/Logger/LogsHttpLogger.php b/src/Logger/LogsHttpLogger.php index 0d350be..9cb515e 100644 --- a/src/Logger/LogsHttpLogger.php +++ b/src/Logger/LogsHttpLogger.php @@ -76,19 +76,9 @@ public function log($level, $message, array $context = array()) { } /** - * Register an event in the cache. - * - * To prevent multiple registration of the same error, we check that identical - * events are not captured twice, thus reducing the final HTTP requests needed. - * - * @param $level - * The severity level. - * @param message - * The message that contains the placeholders. - * @param array $context - * The context as passed from the main Logger. + * {@inheritdoc} */ - public function registerEvent($level, $message, array $context = []) { + public function registerEvent($level, $message, array $context) { if (!$this->isEnabled()) { return; } @@ -183,4 +173,8 @@ public function isEnabled() { public function getUrl() { return $this->config->get('url'); } + + public function getCache() { + return $this->cache; + } } diff --git a/src/Logger/LogsHttpLoggerInterface.php b/src/Logger/LogsHttpLoggerInterface.php index b239c19..35c5f7d 100644 --- a/src/Logger/LogsHttpLoggerInterface.php +++ b/src/Logger/LogsHttpLoggerInterface.php @@ -15,13 +15,19 @@ public function reset(); /** - * Register an event. + * Register an event in the cache. + * + * To prevent multiple registration of the same error, we check that identical + * events are not captured twice, thus reducing the final HTTP requests needed. * * @param $level + * The severity level. * @param message + * The message that contains the placeholders. * @param array $context + * The context as passed from the main Logger. */ - public function registerEvent($level, $message, array $context = []); + public function registerEvent($level, $message, array $context); /** * A getter for the current events. diff --git a/tests/src/Unit/LogsHttpLoggerTest.php b/tests/src/Unit/LogsHttpLoggerTest.php index b48b89a..8eb8af3 100644 --- a/tests/src/Unit/LogsHttpLoggerTest.php +++ b/tests/src/Unit/LogsHttpLoggerTest.php @@ -37,6 +37,20 @@ class LogsHttpLoggerTest extends UnitTestCase { */ protected $severityLevels; + /** + * The message to log. + * + * @var string + */ + protected $message; + + /** + * The context array with the log data. + * + * @var array + */ + protected $context; + /** * {@inheritdoc} @@ -45,6 +59,10 @@ public function setUp() { $this->config = $this->prophesize(ConfigFactoryInterface::class); $this->logMessageParser = $this->prophesize(LogMessageParserInterface::class); $this->severityLevels = RfcLogLevel::getLevels(); + $this->message = $this->randomMachineName(); + $this->context = [ + 'timestamp' => time(), + ]; $this ->config @@ -76,6 +94,28 @@ public function testIsEnabled($enabled, $url, $expected) { $this->assertEquals($expected, $result); } + /** + * Test register event when setting is disabled. + * + * @covers ::registerEvent + */ + public function testRegisterEventDisabled() { + $this + ->config + ->get('enabled') + ->willReturn(FALSE); + + $this + ->config + ->get('url') + ->willReturn($this->randomMachineName()); + + $logger = new LogsHttpLogger($this->config->reveal(), $this->logMessageParser->reveal()); + $logger->registerEvent(RfcLogLevel::CRITICAL, $this->message, $this->context); + + $this->assertEmpty($logger->getCache()); + } + /** * Provides test data to test isEnabled.