* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 * @author Icinga Development Team * */ // {{{ICINGA_LICENSE_HEADER}}} // @codingStandardsIgnoreStart require_once realpath(__DIR__ . '/../../../../../library/Icinga/Test/BaseTestCase.php'); // @codingStandardsIgnoreEnd use Icinga\Test\BaseTestCase; // @codingStandardsIgnoreStart require_once BaseTestCase::$libDir . '/Logger/Logger.php'; require_once BaseTestCase::$libDir . '/Logger/LogWriter.php'; require_once BaseTestCase::$libDir . '/Logger/Writer/StreamWriter.php'; // @codingStandardsIgnoreEnd use \Zend_Config; use Icinga\Logger\Logger; class LoggerTest extends BaseTestCase { /** * @backupStaticAttributes enabled */ public function testLogfileCreation() { $target = tempnam(sys_get_temp_dir(), 'log'); unlink($target); Logger::create( new Zend_Config( array( 'enable' => true, 'level' => Logger::$ERROR, 'type' => 'stream', 'target' => $target ) ) ); $this->assertFileExists($target, 'Logger did not create the log file'); unlink($target); } /** * @backupStaticAttributes enabled * @depends testLogfileCreation */ public function testLoggingErrorMessages() { $target = tempnam(sys_get_temp_dir(), 'log'); unlink($target); Logger::create( new Zend_Config( array( 'enable' => true, 'level' => Logger::$ERROR, 'type' => 'stream', 'target' => $target ) ) ); Logger::error('This is a test error'); $log = file_get_contents($target); unlink($target); $this->assertContains('This is a test error', $log, 'Log does not contain the error "This is a test error"'); } }