/** * Test Logger instantiation * * Pre-conditions: * Case A: Logger instantiated with existing directory * Case B: Logger instantiated with non existing directory * Case C: Logger instantiated with valid level * Case D: Logger instantiated with invalid level * * Post-conditions: * Case A: Logger created * Case B: RuntimeException thrown * Case C: Logger created * Case D: InvalidArgumentException thrown */ public function testLoggerInstantiation() { //Case A $l1 = new Slim_Logger('./logs'); $this->assertEquals(4, $l1->getLevel()); //Case B try { $l2 = new Slim_Logger('./foo'); $this->fail("Did not catch RuntimeException thrown from Logger with non-existant directory"); } catch ( RuntimeException $e) {} //Case C $l3 = new Slim_Logger('./logs', 1); $this->assertEquals(1, $l3->getLevel()); //Case D try { $l4 = new Slim_Logger('./logs', 5); $this->fail("Did not catch RuntimeException thrown from Logger with invalid level"); } catch ( InvalidArgumentException $e) {} }
/** * Test info log */ public function testLogsFatal() { $l = new Slim_Logger($this->logDir, 0); $message = '[FATAL] ' . date('c') . ' - ' . "Test Info\r\n"; $l->error('Test Info'); $l->fatal('Test Info'); $this->assertEquals(file_get_contents($l->getFile()), $message); }