public function testAppendsLogMessages() { $logFile = new File(ABLERON_LOG_DIR . '/FileLoggerTest-testAppendsLogMessages.log'); $logger = new FileLogger($logFile); $logger->error('Message 1'); $logger->warning('Message 2'); $this->assertStringMatchesFormat('%d-%d-%d %d:%d:%d ERROR Message 1%c%d-%d-%d %d:%d:%d WARNING Message 2', $logFile->getContent()); }
public function testAppend() { $tempFile = new File(FileUtil::getTempFileName()); $this->assertTrue($tempFile->append('foobar')); $this->assertSame('foobar', $tempFile->getContent()); $this->assertTrue($tempFile->append('bazfoobar')); $this->assertSame('foobarbazfoobar', $tempFile->getContent()); }
/** * @see \Psr\Log\LoggerInterface::log() */ public function log($level, $message, array $context = array()) { $this->logFile->append($this->buildLogEntry($level, $this->composeMessage($message, $context), $this->getExceptionFromContext($context)) . StringUtil::CHAR_LINE_FEED); }
/** * Tests whether error() works as expected. * * @return void */ public function testError() { $logFile = new File(ABLERON_LOG_DIR . '/LogManagerTest-testError.log'); $logManager = new LogManager(new FileLogger($logFile)); $logManager->error('Error message with {placeholder}', array('placeholder' => 'replacement')); $this->assertStringMatchesFormat('%d-%d-%d %d:%d:%d ERROR Error message with replacement', $logFile->getContent()); }
/** * Tests whether removeDirectory() works correctly. * * @return void */ public function testRemoveDirectory() { FileUtil::createDirectoryIfNotExists(ABLERON_TEMP_DIR . '/testRemoveDirectory/foo/bar/baz'); $file = new File(ABLERON_TEMP_DIR . '/testRemoveDirectory/foo/bar/bar.txt'); $file->append('foobar'); $this->assertTrue(is_file($file->getPath())); FileUtil::removeDirectory(ABLERON_TEMP_DIR . '/testRemoveDirectory'); $this->assertFalse(is_file($file->getPath())); $this->assertFalse(is_dir(ABLERON_TEMP_DIR . '/testRemoveDirectory')); }