2014-05-05 08:41:38 +02:00
|
|
|
<?php
|
2014-05-06 11:18:04 +02:00
|
|
|
class LoggerTest extends AbstractTest
|
2014-05-05 08:41:38 +02:00
|
|
|
{
|
2014-05-05 09:58:18 +02:00
|
|
|
public function testLogging()
|
|
|
|
{
|
2014-05-07 01:14:52 +02:00
|
|
|
$realLogPath = Logger::getLogPath();
|
2014-05-05 09:58:18 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2014-05-07 01:14:52 +02:00
|
|
|
|
|
|
|
public function testPathChanging()
|
|
|
|
{
|
2014-05-15 10:32:53 +02:00
|
|
|
$logPath = TextHelper::absolutePath(Core::getConfig()->rootDir . '/tests/logs/{yyyy}-{mm}-{dd}.log');
|
|
|
|
$realLogPath = TextHelper::absolutePath(Core::getConfig()->rootDir . '/tests/logs/' . date('Y-m-d') . '.log');
|
2014-05-07 01:14:52 +02:00
|
|
|
|
2014-05-15 10:32:53 +02:00
|
|
|
Core::getConfig()->main->logsPath = $logPath;
|
2014-05-07 01:14:52 +02:00
|
|
|
$this->assert->doesNotThrow(function()
|
|
|
|
{
|
|
|
|
Logger::init();
|
|
|
|
});
|
|
|
|
$this->assert->areEqual($realLogPath, Logger::getLogPath());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testDiscarding()
|
|
|
|
{
|
|
|
|
$realLogPath = Logger::getLogPath();
|
|
|
|
|
|
|
|
$this->assert->isFalse(file_exists($realLogPath));
|
|
|
|
|
|
|
|
Logger::bufferChanges();
|
|
|
|
Logger::log('line 1');
|
|
|
|
Logger::log('line 2');
|
|
|
|
Logger::log('line 3');
|
|
|
|
Logger::discardBuffer();
|
|
|
|
|
|
|
|
$this->assert->isFalse(file_exists($realLogPath));
|
|
|
|
Logger::log('line 4');
|
|
|
|
Logger::flush();
|
|
|
|
$this->assert->isTrue(file_exists($realLogPath));
|
|
|
|
|
|
|
|
$x = file_get_contents($realLogPath);
|
|
|
|
$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);
|
|
|
|
}
|
2014-05-05 08:41:38 +02:00
|
|
|
}
|