2014-04-22 08:31:57 -04:00
|
|
|
<?php
|
2026-03-26 12:46:27 -04:00
|
|
|
|
|
|
|
|
// SPDX-FileCopyrightText: 2018 Icinga GmbH <https://icinga.com>
|
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
2014-04-22 08:31:57 -04:00
|
|
|
|
|
|
|
|
namespace Tests\Icinga\Logger\Writer;
|
|
|
|
|
|
2014-11-18 07:11:52 -05:00
|
|
|
use Icinga\Data\ConfigObject;
|
2014-10-31 05:27:17 -04:00
|
|
|
use Icinga\Application\Logger;
|
|
|
|
|
use Icinga\Application\Logger\Writer\FileWriter;
|
2014-04-22 08:31:57 -04:00
|
|
|
use Icinga\Test\BaseTestCase;
|
|
|
|
|
|
2014-10-16 09:58:37 -04:00
|
|
|
class StreamWriterTest extends BaseTestCase
|
2014-04-22 08:31:57 -04:00
|
|
|
{
|
2021-04-09 03:39:10 -04:00
|
|
|
public function setUp(): void
|
2014-04-22 08:31:57 -04:00
|
|
|
{
|
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
|
|
$this->target = tempnam(sys_get_temp_dir(), 'log');
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-09 03:39:10 -04:00
|
|
|
public function tearDown(): void
|
2014-04-22 08:31:57 -04:00
|
|
|
{
|
|
|
|
|
parent::tearDown();
|
|
|
|
|
|
|
|
|
|
unlink($this->target);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testWhetherStreamWriterCreatesMissingFiles()
|
|
|
|
|
{
|
2014-11-18 07:11:52 -05:00
|
|
|
new FileWriter(new ConfigObject(array('file' => $this->target)));
|
2014-04-22 08:31:57 -04:00
|
|
|
$this->assertFileExists($this->target, 'StreamWriter does not create missing files on initialization');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @depends testWhetherStreamWriterCreatesMissingFiles
|
|
|
|
|
*/
|
|
|
|
|
public function testWhetherStreamWriterWritesMessages()
|
|
|
|
|
{
|
2014-11-18 07:11:52 -05:00
|
|
|
$writer = new FileWriter(new ConfigObject(array('file' => $this->target)));
|
2014-10-16 09:58:37 -04:00
|
|
|
$writer->log(Logger::ERROR, 'This is a test error');
|
2014-04-22 08:31:57 -04:00
|
|
|
$log = file_get_contents($this->target);
|
2021-04-09 04:49:17 -04:00
|
|
|
$this->assertStringContainsString('This is a test error', $log, 'StreamWriter does not write log messages');
|
2014-04-22 08:31:57 -04:00
|
|
|
}
|
|
|
|
|
}
|