pickles/tests/classes/LogTest.php
Joshua Sherman 8db383601e More tests and 100% coverage achievements!
Also fixed a few minor bugs and reworked Browser class to not use the constant
UNIT_TESTING so I could get the class to 100% coverage. Adds a dependency of
testing_helpers which I believe is available on Travis CI by default. Up to 75%
coverage, w00t w00t!
2014-01-12 16:09:48 -05:00

103 lines
2.1 KiB
PHP

<?php
class LogTest extends PHPUnit_Framework_TestCase
{
private $config;
public function setUp()
{
$this->config = Config::getInstance();
$this->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);
}
public function testLoggingDisabled()
{
$this->config->data['pickles']['logging'] = false;
$this->assertFalse(Log::error('should return false'));
}
}
?>