<?php
class LoggerTest extends AbstractTest
{
public function testLogging()
$realLogPath = Logger::getLogPath();
try
$this->assert->isFalse(file_exists($realLogPath));
$this->assert->doesNotThrow(function()
Logger::log('Simple text');
});
$this->assert->isTrue(file_exists($realLogPath));
$x = file_get_contents($realLogPath);
$this->assert->isTrue(strpos($x, 'Simple text') !== false);
}
finally
if (file_exists($realLogPath))
unlink($realLogPath);
public function testPathChanging()
$logPath = __DIR__ . '/logs/{yyyy}-{mm}-{dd}.log';
$realLogPath = __DIR__ . '/logs/' . date('Y-m-d') . '.log';
getConfig()->main->logsPath = $logPath;
Logger::init();
$this->assert->areEqual($realLogPath, Logger::getLogPath());
public function testDiscarding()
Logger::bufferChanges();
Logger::log('line 1');
Logger::log('line 2');
Logger::log('line 3');
Logger::discardBuffer();
Logger::log('line 4');
Logger::flush();
$this->assert->isTrue(strpos($x, 'line 1') === false);
$this->assert->isTrue(strpos($x, 'line 2') === false);
$this->assert->isTrue(strpos($x, 'line 3') === false);
$this->assert->isTrue(strpos($x, 'line 4') !== false);