Files
loggerFactory/tests/Options/FileLoggerHandlerOptionTest.php
2025-05-02 15:35:39 +02:00

117 lines
3.2 KiB
PHP

<?php
/**
* Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*
* https://www.d3data.de
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
* @link https://www.oxidmodule.com
*/
namespace D3\LoggerFactory\tests\Options;
use D3\LoggerFactory\Options\FileLoggerHandlerOption;
use D3\LoggerFactory\tests\AbstractTestCase;
use Generator;
use Monolog\Handler\BufferHandler;
use Monolog\Handler\DeduplicationHandler;
use Monolog\Handler\FingersCrossedHandler;
use Monolog\Handler\RotatingFileHandler;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use ReflectionException;
/**
* @coversNothing
*/
class FileLoggerHandlerOptionTest extends AbstractTestCase
{
/**
* @test
* @throws ReflectionException
* @covers \D3\LoggerFactory\Options\FileLoggerHandlerOption::__construct
* @covers \D3\LoggerFactory\Options\FileLoggerHandlerOption::getHandler
* @dataProvider constructDataProvider
*/
public function testConstruct(?int $maxFiles, string $expectedClass): void
{
$sut = new FileLoggerHandlerOption('file/path.log', Logger::INFO, $maxFiles);
$this->assertInstanceOf(
$expectedClass,
$this->callMethod(
$sut,
'getHandler'
)
);
}
public static function constructDataProvider(): Generator
{
yield 'rotating' => [5, RotatingFileHandler::class];
yield 'non rotating' => [null, StreamHandler::class];
}
/**
* @test
* @throws ReflectionException
* @covers \D3\LoggerFactory\Options\FileLoggerHandlerOption::setBuffering
*/
public function testSetBuffering(): void
{
$handlerOption = new FileLoggerHandlerOption('file/path.log', Logger::INFO);
$handlerOption = $this->callMethod(
$handlerOption,
'setBuffering',
);
$this->assertInstanceOf(
BufferHandler::class,
$handlerOption->getHandler()
);
}
/**
* @test
* @throws ReflectionException
* @covers \D3\LoggerFactory\Options\FileLoggerHandlerOption::setLogOnErrorOnly
*/
public function testSetLogOnErrorOnly(): void
{
$handlerOption = new FileLoggerHandlerOption('file/path.log', Logger::INFO);
$handlerOption = $this->callMethod(
$handlerOption,
'setLogOnErrorOnly',
);
$this->assertInstanceOf(
FingersCrossedHandler::class,
$handlerOption->getHandler()
);
}
/**
* @test
* @throws ReflectionException
* @covers \D3\LoggerFactory\Options\FileLoggerHandlerOption::setUnique
*/
public function testSetUnique(): void
{
$handlerOption = new FileLoggerHandlerOption('file/path.log', Logger::INFO);
$handlerOption = $this->callMethod(
$handlerOption,
'setUnique',
);
$this->assertInstanceOf(
DeduplicationHandler::class,
$handlerOption->getHandler()
);
}
}