Beispiel #1
0
 public function testItLogsToFile()
 {
     $logger = new \Wplog\Logging\File\Logger();
     $testLogFile = ABSPATH . '/wplog-testing.log';
     $logger->setLogFile($testLogFile);
     $event = new OptionEvent();
     $event->setBody('Hello World {user}!');
     $event->setSeverity('notice');
     $event->setContext(['user' => 'John Doe']);
     $logger->debug('Hello World!', [], $event);
     $logContents = file_get_contents($testLogFile);
     $this->assertRegExp('%Hello World John Doe%imu', $logContents);
     unlink($testLogFile);
 }
Beispiel #2
0
 function testItWritesLogsToDatabase()
 {
     global $wpdb;
     $logger = new Logger();
     $event = new OptionEvent();
     $event->setBody('Hello World {user}!');
     $event->setSeverity('notice');
     $event->setContext(['user' => 'John Doe']);
     $logger->log('notice', 'Hello World {user}!', ['user' => 'John Doe'], $event);
     $result = $wpdb->get_row(sprintf('SELECT * FROM %s.%s WHERE body LIKE "%%World%%"', DB_NAME, $wpdb->prefix . 'wplog'));
     $this->assertNotEmpty($result);
     $this->assertStringStartsWith('Hello World', $result->body);
     $this->assertStringEndsWith('Doe!', $result->body);
 }