* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 * @author Icinga Development Team * */ // {{{ICINGA_LICENSE_HEADER}}} namespace Tests\Icinga\Application; // @codingStandardsIgnoreStart require_once realpath(__DIR__ . '/../../../../../library/Icinga/Test/BaseTestCase.php'); // @codingStandardsIgnoreEnd use Zend_Config; use Zend_Log; use Icinga\Application\Logger; use Icinga\Test\BaseTestCase; class LoggerTest extends BaseTestCase { /** * @backupStaticAttributes enabled */ public function testLogfileCreation() { $target = tempnam(sys_get_temp_dir(), 'log'); unlink($target); Logger::create( new Zend_Config( array( '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( 'type' => 'stream', 'priority' => Zend_Log::ERR, '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"'); } }