2014-04-22 14:31:57 +02:00
|
|
|
<?php
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
|
|
|
|
namespace Tests\Icinga\Logger\Writer;
|
|
|
|
|
2014-11-18 13:11:52 +01:00
|
|
|
use Icinga\Data\ConfigObject;
|
2014-10-31 10:27:17 +01:00
|
|
|
use Icinga\Application\Logger;
|
|
|
|
use Icinga\Application\Logger\Writer\FileWriter;
|
2014-04-22 14:31:57 +02:00
|
|
|
use Icinga\Test\BaseTestCase;
|
|
|
|
|
2014-10-16 15:58:37 +02:00
|
|
|
class StreamWriterTest extends BaseTestCase
|
2014-04-22 14:31:57 +02:00
|
|
|
{
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->target = tempnam(sys_get_temp_dir(), 'log');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function tearDown()
|
|
|
|
{
|
|
|
|
parent::tearDown();
|
|
|
|
|
|
|
|
unlink($this->target);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testWhetherStreamWriterCreatesMissingFiles()
|
|
|
|
{
|
2014-11-18 13:11:52 +01:00
|
|
|
new FileWriter(new ConfigObject(array('file' => $this->target)));
|
2014-04-22 14:31:57 +02:00
|
|
|
$this->assertFileExists($this->target, 'StreamWriter does not create missing files on initialization');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testWhetherStreamWriterCreatesMissingFiles
|
|
|
|
*/
|
|
|
|
public function testWhetherStreamWriterWritesMessages()
|
|
|
|
{
|
2014-11-18 13:11:52 +01:00
|
|
|
$writer = new FileWriter(new ConfigObject(array('file' => $this->target)));
|
2014-10-16 15:58:37 +02:00
|
|
|
$writer->log(Logger::ERROR, 'This is a test error');
|
2014-04-22 14:31:57 +02:00
|
|
|
$log = file_get_contents($this->target);
|
|
|
|
$this->assertContains('This is a test error', $log, 'StreamWriter does not write log messages');
|
|
|
|
}
|
|
|
|
}
|