|
@@ -13,47 +13,47 @@ class LoggerTest extends PHPUnit_Extensions_OutputTestCase {
|
|
|
$this->logger = new Logger();
|
|
$this->logger = new Logger();
|
|
|
$this->logger->set_property('name', NAME);
|
|
$this->logger->set_property('name', NAME);
|
|
|
$this->logger->set_format(FORMAT);
|
|
$this->logger->set_format(FORMAT);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
is_dir('build') || mkdir('build');
|
|
is_dir('build') || mkdir('build');
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
function assert_dumps($expected) {
|
|
function assert_dumps($expected) {
|
|
|
$this->assertEquals($this->logger->dumps(), $expected);
|
|
$this->assertEquals($this->logger->dumps(), $expected);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
function test_set_directory() {
|
|
function test_set_directory() {
|
|
|
$this->logger->set_directory('logs');
|
|
$this->logger->set_directory('logs');
|
|
|
$this->assertAttributeEquals('logs/', 'log_directory', $this->logger);
|
|
$this->assertAttributeEquals('logs/', 'log_directory', $this->logger);
|
|
|
$this->logger->set_directory('logs/');
|
|
$this->logger->set_directory('logs/');
|
|
|
$this->assertAttributeEquals('logs/', 'log_directory', $this->logger);
|
|
$this->assertAttributeEquals('logs/', 'log_directory', $this->logger);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
function test_set_format() {
|
|
function test_set_format() {
|
|
|
$this->logger->set_format('foo');
|
|
$this->logger->set_format('foo');
|
|
|
$this->assertAttributeEquals('foo', 'format', $this->logger);
|
|
$this->assertAttributeEquals('foo', 'format', $this->logger);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
function test_set_dump_format_success() {
|
|
function test_set_dump_format_success() {
|
|
|
$this->logger->set_dump_format('html');
|
|
$this->logger->set_dump_format('html');
|
|
|
$this->assertAttributeEquals('html', 'dump_format', $this->logger);
|
|
$this->assertAttributeEquals('html', 'dump_format', $this->logger);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* @expectedException InvalidArgumentException
|
|
* @expectedException InvalidArgumentException
|
|
|
*/
|
|
*/
|
|
|
function test_set_dump_format_failure() {
|
|
function test_set_dump_format_failure() {
|
|
|
$this->logger->set_dump_format('foo');
|
|
$this->logger->set_dump_format('foo');
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
function test_get_format() {
|
|
function test_get_format() {
|
|
|
$this->assertEquals($this->logger->get_format(), FORMAT);
|
|
$this->assertEquals($this->logger->get_format(), FORMAT);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
function test_get_level() {
|
|
function test_get_level() {
|
|
|
$this->assertEquals($this->logger->get_level(), Logger::WARNING);
|
|
$this->assertEquals($this->logger->get_level(), Logger::WARNING);
|
|
|
$this->assertEquals($this->logger->get_level_name(), 'WARNING');
|
|
$this->assertEquals($this->logger->get_level_name(), 'WARNING');
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* @depends test_get_level
|
|
* @depends test_get_level
|
|
|
*/
|
|
*/
|
|
@@ -67,17 +67,17 @@ class LoggerTest extends PHPUnit_Extensions_OutputTestCase {
|
|
|
$this->logger->set_level(Logger::ERROR);
|
|
$this->logger->set_level(Logger::ERROR);
|
|
|
$this->assertEquals($this->logger->get_level(), Logger::ERROR);
|
|
$this->assertEquals($this->logger->get_level(), Logger::ERROR);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
function test_format() {
|
|
function test_format() {
|
|
|
$this->logger->error('test message');
|
|
$this->logger->error('test message');
|
|
|
$this->assert_dumps('ERROR: test message');
|
|
$this->assert_dumps('ERROR: test message');
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
function test_set_property() {
|
|
function test_set_property() {
|
|
|
$this->logger->set_property('name', 'Logger');
|
|
$this->logger->set_property('name', 'Logger');
|
|
|
$this->assertEquals($this->logger->get_formatted_property('name'), 'Logger');
|
|
$this->assertEquals($this->logger->get_formatted_property('name'), 'Logger');
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* @depends test_format
|
|
* @depends test_format
|
|
|
*/
|
|
*/
|
|
@@ -86,7 +86,7 @@ class LoggerTest extends PHPUnit_Extensions_OutputTestCase {
|
|
|
$this->logger->clear();
|
|
$this->logger->clear();
|
|
|
$this->assert_dumps('');
|
|
$this->assert_dumps('');
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* @depends test_set_level
|
|
* @depends test_set_level
|
|
|
* @depends test_clear
|
|
* @depends test_clear
|
|
@@ -103,7 +103,7 @@ class LoggerTest extends PHPUnit_Extensions_OutputTestCase {
|
|
|
$this->logger->debug('test message');
|
|
$this->logger->debug('test message');
|
|
|
$this->assert_dumps('DEBUG: test message');
|
|
$this->assert_dumps('DEBUG: test message');
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
function test_get_formatted_property() {
|
|
function test_get_formatted_property() {
|
|
|
$this->assertEquals($this->logger->get_formatted_property('name'), NAME);
|
|
$this->assertEquals($this->logger->get_formatted_property('name'), NAME);
|
|
|
$this->assertEquals($this->logger->get_formatted_property('loglevel'), 'WARNING');
|
|
$this->assertEquals($this->logger->get_formatted_property('loglevel'), 'WARNING');
|
|
@@ -116,13 +116,13 @@ class LoggerTest extends PHPUnit_Extensions_OutputTestCase {
|
|
|
$this->setExpectedException('\InvalidArgumentException');
|
|
$this->setExpectedException('\InvalidArgumentException');
|
|
|
$this->logger->get_formatted_property('foo');
|
|
$this->logger->get_formatted_property('foo');
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
function test_dumps_property_format() {
|
|
function test_dumps_property_format() {
|
|
|
$this->logger->warning('test message');
|
|
$this->logger->warning('test message');
|
|
|
$this->logger->set_format('%(name): %(level): %(message)');
|
|
$this->logger->set_format('%(name): %(level): %(message)');
|
|
|
$this->assert_dumps(NAME.': WARNING: test message');
|
|
$this->assert_dumps(NAME.': WARNING: test message');
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* @depends test_process_level
|
|
* @depends test_process_level
|
|
|
*/
|
|
*/
|
|
@@ -131,7 +131,7 @@ class LoggerTest extends PHPUnit_Extensions_OutputTestCase {
|
|
|
$this->expectOutputString('WARNING: test message');
|
|
$this->expectOutputString('WARNING: test message');
|
|
|
$this->logger->dump();
|
|
$this->logger->dump();
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* @depends test_process_level
|
|
* @depends test_process_level
|
|
|
*/
|
|
*/
|
|
@@ -141,7 +141,7 @@ class LoggerTest extends PHPUnit_Extensions_OutputTestCase {
|
|
|
$this->expectOutputString('<strong>Log:</strong><br /><pre>WARNING: test message</pre>');
|
|
$this->expectOutputString('<strong>Log:</strong><br /><pre>WARNING: test message</pre>');
|
|
|
$this->logger->dump();
|
|
$this->logger->dump();
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
function test_save() {
|
|
function test_save() {
|
|
|
$this->logger->warning('test message');
|
|
$this->logger->warning('test message');
|
|
|
$this->logger->save(LOGFILE);
|
|
$this->logger->save(LOGFILE);
|
|
@@ -151,20 +151,20 @@ class LoggerTest extends PHPUnit_Extensions_OutputTestCase {
|
|
|
$this->assertStringEqualsFile(LOGFILE, "WARNING: test message\nWARNING: another test message");
|
|
$this->assertStringEqualsFile(LOGFILE, "WARNING: test message\nWARNING: another test message");
|
|
|
unlink(LOGFILE);
|
|
unlink(LOGFILE);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
function find_logfile() {
|
|
function find_logfile() {
|
|
|
$files = scandir(LOGDIR);
|
|
$files = scandir(LOGDIR);
|
|
|
$this->assertEquals(3, count($files));
|
|
$this->assertEquals(3, count($files));
|
|
|
return $files[2];
|
|
return $files[2];
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* @depends test_save
|
|
* @depends test_save
|
|
|
*/
|
|
*/
|
|
|
function test_dump_file_regular() {
|
|
function test_dump_file_regular() {
|
|
|
$this->logger->set_directory(LOGDIR);
|
|
$this->logger->set_directory(LOGDIR);
|
|
|
$this->logger->set_dump_format('file');
|
|
$this->logger->set_dump_format('file');
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
$this->logger->warning('test message');
|
|
$this->logger->warning('test message');
|
|
|
$this->logger->dump();
|
|
$this->logger->dump();
|
|
|
$filename = $this->find_logfile();
|
|
$filename = $this->find_logfile();
|
|
@@ -172,26 +172,12 @@ class LoggerTest extends PHPUnit_Extensions_OutputTestCase {
|
|
|
unlink(LOGDIR . $filename);
|
|
unlink(LOGDIR . $filename);
|
|
|
$this->assertRegExp('/^log_\d{2}-\d{2}-\d{4}_\d{2}-\d{2}-\d{2}.log$/', $filename);
|
|
$this->assertRegExp('/^log_\d{2}-\d{2}-\d{4}_\d{2}-\d{2}-\d{2}.log$/', $filename);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * @depends test_dump_file_regular
|
|
|
|
|
- */
|
|
|
|
|
- function test_dump_file_prefix() {
|
|
|
|
|
- $this->logger->set_directory(LOGDIR);
|
|
|
|
|
- $this->logger->set_dump_format('file');
|
|
|
|
|
-
|
|
|
|
|
- $this->logger->warning('test message');
|
|
|
|
|
- $this->logger->dump('error');
|
|
|
|
|
- $filename = $this->find_logfile();
|
|
|
|
|
- $this->assertStringEqualsFile(LOGDIR . $filename, 'WARNING: test message');
|
|
|
|
|
- unlink(LOGDIR . $filename);
|
|
|
|
|
- $this->assertRegExp('/^error_\d{2}-\d{2}-\d{4}_\d{2}-\d{2}-\d{2}.log$/', $filename);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
function test_handle_exception() {
|
|
function test_handle_exception() {
|
|
|
- $this->logger->handle_exception(new Exception('test message'));
|
|
|
|
|
|
|
+ $this->logger->set_dump_format('none');
|
|
|
|
|
+ $this->logger->handle_exception(new RuntimeException('test message'));
|
|
|
$this->assertNotEquals($this->logger->dumps(), '');
|
|
$this->assertNotEquals($this->logger->dumps(), '');
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-?>
|
|
|
|
|
|
|
+?>
|