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

99 lines
2.7 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\LoggerFactory;
use D3\LoggerFactory\Options\OxidLoggerHandlerOption;
use D3\LoggerFactory\tests\AbstractTestCase;
use Generator;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use ReflectionException;
use RuntimeException;
/**
* @coversNothing
*/
class OxidLoggerHandlerOptionTest extends AbstractTestCase
{
/**
* @test
* @throws ReflectionException
* @covers \D3\LoggerFactory\Options\OxidLoggerHandlerOption::__construct
* @covers \D3\LoggerFactory\Options\OxidLoggerHandlerOption::getHandler
* @dataProvider inOxidDataProvider
*/
public function testConstruct(bool $inOxid, bool $expectException): void
{
if ($expectException) {
$this->expectException(RuntimeException::class);
}
$sut = $this->getMockBuilder(OxidLoggerHandlerOption::class)
->onlyMethods(['isInOXIDFramework'])
->disableOriginalConstructor()
->getMock();
$sut->method('isInOXIDFramework')->willReturn($inOxid);
$this->callMethod(
$sut,
'__construct',
['fileName', Logger::INFO]
);
$this->assertInstanceOf(
StreamHandler::class,
$this->callMethod(
$sut,
'getHandler'
)
);
}
public static function inOxidDataProvider(): Generator
{
yield 'is in OXID' => [true, false];
yield 'is not in OXID' => [false, true];
}
/**
* @test
* @throws ReflectionException
* @covers \D3\LoggerFactory\Options\OxidLoggerHandlerOption::getOxidLogPath
* @dataProvider inOxidDataProvider
*/
public function testGetOxidLogPath(bool $inOxid, bool $expectException): void
{
if ($expectException) {
$this->expectException(RuntimeException::class);
}
$sut = $this->getMockBuilder(OxidLoggerHandlerOption::class)
->onlyMethods(['isInOXIDFramework'])
->disableOriginalConstructor()
->getMock();
$sut->method('isInOXIDFramework')->willReturn($inOxid);
$this->assertStringEndsWith(
'fixture.log',
$this->callMethod(
$sut,
'getOxidLogPath',
['fixture.log']
)
);
}
}