'is a test', 'level' => strtoupper(LogLevel::INFO), 'timestamp' => (new \DateTimeImmutable())->format('c'), ]; $handler->handle($vars); $this->assertEquals(1, count($storage)); $this->assertEquals($storage[0], sprintf('%s [%s]: %s', $vars['timestamp'], $vars['level'], $vars['message'])); $this->testLogLevel(); $this->testCustomFormat(); } private function testLogLevel() { $storage = []; $handler = new MemoryHandler($storage, LogLevel::ERROR); // Should not log INFO $handler->handle([ 'level' => LogLevel::INFO, 'message' => 'info message', 'timestamp' => '2023-01-01 00:00:00' ]); $this->assertEquals(0, count($storage)); // Should log ERROR $handler->handle([ 'level' => LogLevel::ERROR, 'message' => 'error message', 'timestamp' => '2023-01-01 00:00:00' ]); $this->assertEquals(1, count($storage)); } private function testCustomFormat() { $storage = []; $handler = new MemoryHandler($storage); $handler->setFormat('[%level%] %message%'); $handler->handle([ 'level' => LogLevel::INFO, 'message' => 'custom format', 'timestamp' => '2023-01-01 00:00:00' ]); $this->assertEquals('[INFO] custom format', $storage[0]); } }