log(LogLevel::EMERGENCY, 'testEmergency1', ["context1" => "value1", "context2" => "value2"]); $logger->log(LogLevel::EMERGENCY, 'testEmergency2', ["context3" => "value3", "context4" => "value4"]); $entries = $logger->get(LogLevel::EMERGENCY); $this->assertEquals(2, count($entries)); $this->assertEquals(0, count($logger->get(LogLevel::ALERT))); $this->assertEquals(0, count($logger->get(LogLevel::CRITICAL))); $this->assertEquals(0, count($logger->get(LogLevel::DEBUG))); $this->assertEquals(0, count($logger->get(LogLevel::ERROR))); $this->assertEquals(0, count($logger->get(LogLevel::INFO))); $this->assertEquals(0, count($logger->get(LogLevel::NOTICE))); $this->assertEquals(0, count($logger->get(LogLevel::WARNING))); $this->assertEquals('testEmergency1', $entries[0]['message']); $this->assertEquals(["context1" => "value1", "context2" => "value2"], $entries[0]['context']); $this->assertEquals('testEmergency2', $entries[1]['message']); $this->assertEquals(["context3" => "value3", "context4" => "value4"], $entries[1]['context']); $this->assertTrue($logger->has(LogLevel::EMERGENCY, 'testEmergency1')); $this->assertTrue($logger->has(LogLevel::EMERGENCY, 'testEmergency2')); $this->assertFalse($logger->has(LogLevel::EMERGENCY, 'I haven\'t been logged')); } public function testLogBadLevel() { $logger = new TestLogger(); $logger->log('BAD_LEVEL', 'testMessage'); $this->assertEquals(1, count($logger->get(LogLevel::ERROR))); } public function testGetBadLevel() { $this->expectException(common_exception_InconsistentData::class); $logger = new TestLogger(); $logger->get('BAD_LEVEL'); } public function testHasBadLevel() { $this->expectException(common_exception_InconsistentData::class); $logger = new TestLogger(); $logger->has('BAD_LEVEL', 'testMessage'); } }