pickles/tests/classes/LogTest.php
Joshua Sherman bfa35794b5 Cleaned up old code and wrote more tests
Log class is fully tested, Dynamic class is nearly complete but I wanted to see what Travis would bark about regarding LESS and SASS
2014-01-02 18:16:15 -05:00

94 lines
2 KiB
PHP

<?php
class LogTest extends PHPUnit_Framework_TestCase
{
public static function setUpBeforeClass()
{
$config = Config::getInstance();
$config->data['pickles']['logging'] = true;
}
public static function tearDownAfterClass()
{
File::removeDirectory(LOG_PATH);
}
public function testInformation()
{
Log::information('information');
$file = LOG_PATH . date('Y/m/d/') . 'information.log';
$data = file($file);
$line = $data[count($data) - 1];
$this->assertRegExp('/^\d{2}:\d{2}:\d{2} .+ information$/', $line);
}
public function testWarning()
{
Log::warning('warning');
$file = LOG_PATH . date('Y/m/d/') . 'warning.log';
$data = file($file);
$line = $data[count($data) - 1];
$this->assertRegExp('/^\d{2}:\d{2}:\d{2} .+ warning$/', $line);
}
public function testError()
{
Log::error('error');
$file = LOG_PATH . date('Y/m/d/') . 'error.log';
$data = file($file);
$line = $data[count($data) - 1];
$this->assertRegExp('/^\d{2}:\d{2}:\d{2} .+ error$/', $line);
}
public function testSlowQuery()
{
Log::slowQuery('slow query');
$file = LOG_PATH . date('Y/m/d/') . 'slow_query.log';
$data = file($file);
$line = $data[count($data) - 1];
$this->assertRegExp('/^\d{2}:\d{2}:\d{2} .+ slow query$/', $line);
}
public function testTransaction()
{
Log::transaction('transaction');
$file = LOG_PATH . date('Y/m/d/') . 'transaction.log';
$data = file($file);
$line = $data[count($data) - 1];
$this->assertRegExp('/^\d{2}:\d{2}:\d{2} .+ transaction$/', $line);
}
public function testPHPError()
{
Log::phperror('php error');
$file = LOG_PATH . date('Y/m/d/') . 'php_error.log';
$data = file($file);
$line = $data[count($data) - 1];
$this->assertRegExp('/^php error$/', $line);
}
public function testQuery()
{
Log::query('query');
$file = LOG_PATH . date('Y/m/d/') . 'query.log';
$data = file($file);
$line = $data[count($data) - 1];
$this->assertRegExp('/^\d{2}:\d{2}:\d{2} .+ query$/', $line);
}
}
?>