public function testDecide() { $filter = new LoggerFilterDenyAll(); $events = array(LoggerTestHelper::getTraceEvent(), LoggerTestHelper::getDebugEvent(), LoggerTestHelper::getInfoEvent(), LoggerTestHelper::getWarnEvent(), LoggerTestHelper::getErrorEvent(), LoggerTestHelper::getFatalEvent()); foreach ($events as $event) { $actual = $filter->decide($event); self::assertEquals(LoggerFilter::DENY, $actual); } }
public function testWarnLayout() { $event = LoggerTestHelper::getWarnEvent("testmessage"); $layout = new LoggerLayoutXml(); $layout->activateOptions(); $actual = $layout->format($event); $thread = $event->getThreadName(); $timestamp = number_format($event->getTimeStamp() * 1000, 0, '', ''); $expected = "<log4php:event logger=\"test\" level=\"WARN\" thread=\"{$thread}\" timestamp=\"{$timestamp}\">" . PHP_EOL . "<log4php:message><![CDATA[testmessage]]></log4php:message>" . PHP_EOL . "<log4php:locationInfo class=\"LoggerLoggingEvent\" file=\"NA\" line=\"NA\" " . "method=\"getLocationInformation\" />" . PHP_EOL . "</log4php:event>" . PHP_EOL; self::assertEquals($expected, $actual); }
public function testSimpleLogging() { $appender = $this->createRolloverAppender(); $event = LoggerTestHelper::getWarnEvent("my message123"); for ($i = 0; $i < 1000; $i++) { $appender->append($event); } $appender->append(LoggerTestHelper::getWarnEvent("my messageXYZ")); $appender->close(); $file = PHPUNIT_TEMP_DIR . '/TEST-rolling.txt'; $data = file($file); $line = $data[count($data) - 1]; $e = "WARN - my messageXYZ" . PHP_EOL; self::assertEquals($e, $line); $file = PHPUNIT_TEMP_DIR . '/TEST-rolling.txt.1'; $this->checkFileContent($file); $file = PHPUNIT_TEMP_DIR . '/TEST-rolling.txt.2'; $this->checkFileContent($file); // Should not roll over three times $this->assertFalse(file_exists(PHPUNIT_TEMP_DIR . '/TEST-rolling.txt.3')); }
public function testChangedDateFormat() { $event = LoggerTestHelper::getWarnEvent("my message"); $appender = new LoggerAppenderDailyFile(); $appender->setDatePattern('Y'); $appender->setFile(PHPUNIT_TEMP_DIR . '/TEST-daily.txt.%s'); $appender->activateOptions(); $appender->append($event); $appender->close(); $actual = file_get_contents(PHPUNIT_TEMP_DIR . '/TEST-daily.txt.' . date("Y")); $expected = "WARN - my message" . PHP_EOL; self::assertEquals($expected, $actual); }