add tests
This commit is contained in:
@ -26,17 +26,22 @@ class LoggerBuilder
|
||||
{
|
||||
public function build(string $loggerName, Options $options): Logger
|
||||
{
|
||||
$logger = new Logger($loggerName);
|
||||
$logger = $this->getLogger($loggerName);
|
||||
|
||||
/** @var OptionInterface $option */
|
||||
foreach ($options->getAll() as $option) {
|
||||
if ($option instanceof HandlerOptionInterface) {
|
||||
$logger->pushHandler( $option->getHandler() );
|
||||
$logger->pushHandler($option->getHandler());
|
||||
} elseif ($option instanceof ProcessorOptionInterface) {
|
||||
$logger->pushProcessor( $option->getProcessor() );
|
||||
$logger->pushProcessor($option->getProcessor());
|
||||
}
|
||||
}
|
||||
|
||||
return $logger;
|
||||
}
|
||||
}
|
||||
|
||||
protected function getLogger($loggerName): Logger
|
||||
{
|
||||
return new Logger($loggerName);
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ class OxidLoggerHandlerOption extends AbstractHandlerOption implements HandlerOp
|
||||
*/
|
||||
public function __construct(string $fileName, int $logLevel = Logger::ERROR)
|
||||
{
|
||||
if (!class_exists(Registry::class)) {
|
||||
if (!$this->isInOXIDFramework()) {
|
||||
throw new RuntimeException(__METHOD__.' can executed in OXID eShop installations only');
|
||||
}
|
||||
|
||||
@ -44,10 +44,18 @@ class OxidLoggerHandlerOption extends AbstractHandlerOption implements HandlerOp
|
||||
|
||||
public function getOxidLogPath(string $fileName): string
|
||||
{
|
||||
if (!class_exists(Registry::class)) {
|
||||
if (!$this->isInOXIDFramework()) {
|
||||
throw new RuntimeException(__METHOD__.' can executed in OXID eShop installations only');
|
||||
}
|
||||
|
||||
return OX_BASE_PATH . '/log' . DIRECTORY_SEPARATOR . $fileName;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
protected function isInOXIDFramework(): bool
|
||||
{
|
||||
return class_exists(Registry::class);
|
||||
}
|
||||
}
|
||||
|
75
tests/AbstractTestCase.php
Normal file
75
tests/AbstractTestCase.php
Normal file
@ -0,0 +1,75 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\LoggerFactory\tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use ReflectionClass;
|
||||
use ReflectionException;
|
||||
|
||||
abstract class AbstractTestCase extends TestCase
|
||||
{
|
||||
/**
|
||||
* Calls a private or protected object method.
|
||||
*
|
||||
* @param object $object
|
||||
* @param string $methodName
|
||||
* @param array $arguments
|
||||
*
|
||||
* @return mixed
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function callMethod(object $object, string $methodName, array $arguments = [])
|
||||
{
|
||||
$class = new ReflectionClass($object);
|
||||
$method = $class->getMethod($methodName);
|
||||
$method->setAccessible(true);
|
||||
return $method->invokeArgs($object, $arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a private or protected property in defined class instance
|
||||
*
|
||||
* @param object $object
|
||||
* @param string $valueName
|
||||
* @param $value
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function setValue(object $object, string $valueName, $value): void
|
||||
{
|
||||
$reflection = new ReflectionClass($object);
|
||||
$property = $reflection->getProperty($valueName);
|
||||
$property->setAccessible(true);
|
||||
$property->setValue($object, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* get a private or protected property from defined class instance
|
||||
*
|
||||
* @param object $object
|
||||
* @param string $valueName
|
||||
* @return mixed
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function getValue(object $object, string $valueName)
|
||||
{
|
||||
$reflection = new ReflectionClass($object);
|
||||
$property = $reflection->getProperty($valueName);
|
||||
$property->setAccessible(true);
|
||||
return $property->getValue($object);
|
||||
}
|
||||
}
|
@ -13,7 +13,9 @@
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
namespace D3\GuzzleFactory\tests\Helpers;
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\LoggerFactory\tests\Helpers;
|
||||
|
||||
use Monolog\Logger;
|
||||
|
||||
|
24
tests/Helpers/UnknownOption.php
Normal file
24
tests/Helpers/UnknownOption.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\LoggerFactory\tests\Helpers;
|
||||
|
||||
use D3\LoggerFactory\Options\OptionInterface;
|
||||
|
||||
class UnknownOption implements OptionInterface
|
||||
{
|
||||
}
|
@ -13,8 +13,10 @@
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
use D3\GuzzleFactory\tests\Helpers\OxidRegistryStub;
|
||||
declare(strict_types=1);
|
||||
|
||||
use D3\LoggerFactory\tests\Helpers\OxidRegistryStub;
|
||||
|
||||
const OX_BASE_PATH = __DIR__;
|
||||
|
||||
class_alias(OxidRegistryStub::class, '\OxidEsales\Eshop\Core\Registry');
|
||||
class_alias(OxidRegistryStub::class, 'OxidEsales\Eshop\Core\Registry');
|
||||
|
93
tests/LoggerBuilderTest.php
Normal file
93
tests/LoggerBuilderTest.php
Normal file
@ -0,0 +1,93 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\LoggerFactory\tests;
|
||||
|
||||
use D3\LoggerFactory\LoggerBuilder;
|
||||
use D3\LoggerFactory\LoggerFactory;
|
||||
use D3\LoggerFactory\Options;
|
||||
use D3\LoggerFactory\Options\FileLoggerHandlerOption;
|
||||
use D3\LoggerFactory\Options\MailLoggerHandlerOption;
|
||||
use D3\LoggerFactory\Options\OtherLoggerHandlerOption;
|
||||
use D3\LoggerFactory\Options\OxidLoggerHandlerOption;
|
||||
use D3\LoggerFactory\Options\SensitiveFilterProcessorOption;
|
||||
use D3\LoggerFactory\Options\UidProcessorOption;
|
||||
use D3\LoggerFactory\tests\Helpers\UnknownOption;
|
||||
use Monolog\Handler\FirePHPHandler;
|
||||
use Monolog\Logger;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
use ReflectionException;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* @coversNothing
|
||||
*/
|
||||
class LoggerBuilderTest extends AbstractTestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LoggerFactory\LoggerBuilder::build
|
||||
*/
|
||||
public function testBuild(): void
|
||||
{
|
||||
$loggerMock = $this->getMockBuilder(Logger::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods(['pushProcessor', 'pushHandler'])
|
||||
->getMock();
|
||||
$loggerMock->expects($this->once())->method('pushProcessor');
|
||||
$loggerMock->expects($this->once())->method('pushHandler');
|
||||
|
||||
$sut = $this->getMockBuilder(LoggerBuilder::class)
|
||||
->onlyMethods(['getLogger'])
|
||||
->getMock();
|
||||
$sut->method('getLogger')->willReturn($loggerMock);
|
||||
|
||||
$options = new Options();
|
||||
$options->add(new FileLoggerHandlerOption('file/path.log', Logger::INFO, 5));
|
||||
$options->add(new UidProcessorOption());
|
||||
$options->add(new UnknownOption());
|
||||
|
||||
$this->assertInstanceOf(
|
||||
Logger::class,
|
||||
$this->callMethod(
|
||||
$sut,
|
||||
'build',
|
||||
['nameFixture', $options]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LoggerFactory\LoggerBuilder::getLogger
|
||||
*/
|
||||
public function testGetLogger(): void
|
||||
{
|
||||
$sut = new LoggerBuilder();
|
||||
|
||||
$this->assertInstanceOf(
|
||||
Logger::class,
|
||||
$this->callMethod(
|
||||
$sut,
|
||||
'getLogger',
|
||||
['nameFixture']
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
@ -13,88 +13,304 @@
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\LoggerFactory\tests;
|
||||
|
||||
use D3\LoggerFactory\LoggerBuilder;
|
||||
use D3\LoggerFactory\LoggerFactory;
|
||||
use Generator;
|
||||
use Monolog\Handler\RotatingFileHandler;
|
||||
use Monolog\Handler\StreamHandler;
|
||||
use D3\LoggerFactory\Options;
|
||||
use D3\LoggerFactory\Options\FileLoggerHandlerOption;
|
||||
use D3\LoggerFactory\Options\MailLoggerHandlerOption;
|
||||
use D3\LoggerFactory\Options\OtherLoggerHandlerOption;
|
||||
use D3\LoggerFactory\Options\OtherProcessorOption;
|
||||
use D3\LoggerFactory\Options\OxidLoggerHandlerOption;
|
||||
use D3\LoggerFactory\Options\SensitiveFilterProcessorOption;
|
||||
use D3\LoggerFactory\Options\UidProcessorOption;
|
||||
use Monolog\Handler\FirePHPHandler;
|
||||
use Monolog\Logger;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Monolog\Processor\TagProcessor;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
use ReflectionException;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* @coversNothing
|
||||
*/
|
||||
class LoggerFactoryTest extends ApiTestCase
|
||||
class LoggerFactoryTest extends AbstractTestCase
|
||||
{
|
||||
use SpecialHandlersTestTrait;
|
||||
use ProcessorsTestTrait;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @return void
|
||||
* @covers \D3\LoggerFactory\LoggerFactory::create
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LoggerFactory\LoggerFactory::getOxidLoggerHandlerOption
|
||||
*/
|
||||
public function testCreate(): void
|
||||
public function testGetOxidLoggerHandlerOption(): void
|
||||
{
|
||||
$instance = LoggerFactory::create();
|
||||
$sut = LoggerFactory::create();
|
||||
|
||||
$this->assertInstanceOf(LoggerFactory::class, $instance);
|
||||
if (!class_exists(Registry::class)) {
|
||||
$this->expectException(RuntimeException::class);
|
||||
}
|
||||
|
||||
$this->assertInstanceOf(
|
||||
OxidLoggerHandlerOption::class,
|
||||
$this->callMethod(
|
||||
$sut,
|
||||
'getOxidLoggerHandlerOption',
|
||||
['fileNameFixture']
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @covers \D3\LoggerFactory\LoggerFactory::addFileHandler
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LoggerFactory\LoggerFactory::getFileLogger
|
||||
* @covers \D3\LoggerFactory\LoggerFactory::getFileLoggerStreamHandler
|
||||
* @dataProvider getFileLoggerDataProvider
|
||||
*/
|
||||
public function testGetFileLogger(int $logLevel, ?int $maxFiles, string $expectedHandlerClass): void
|
||||
public function testAddFileHandler(): void
|
||||
{
|
||||
$sut = $this->getMockBuilder(LoggerFactory::class)
|
||||
->onlyMethods(['applySpecialHandlers'])
|
||||
->getMock();
|
||||
$sut->expects($this->once())->method('applySpecialHandlers')->willReturnArgument(0);
|
||||
$sut = LoggerFactory::create();
|
||||
|
||||
/** @var Logger|MockObject $logger */
|
||||
$logger = $this->callMethod(
|
||||
$optionsMock = $this->getMockBuilder(Options::class)
|
||||
->onlyMethods(['add'])
|
||||
->getMock();
|
||||
$optionsMock->expects($this->once())->method('add');
|
||||
|
||||
$this->setValue(
|
||||
$sut,
|
||||
'getFileLogger',
|
||||
['nameFixture', 'file/path.log', $logLevel, $maxFiles]
|
||||
'options',
|
||||
$optionsMock
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(Logger::class, $logger);
|
||||
$this->assertInstanceOf($expectedHandlerClass, $logger->getHandlers()[0]);
|
||||
}
|
||||
|
||||
public static function getFileLoggerDataProvider(): Generator
|
||||
{
|
||||
yield 'no rotation' => [Logger::INFO, null, StreamHandler::class];
|
||||
yield 'rotation 1' => [Logger::ERROR, 1, RotatingFileHandler::class];
|
||||
yield 'rotation 20' => [Logger::DEBUG, 20, RotatingFileHandler::class];
|
||||
$this->assertInstanceOf(
|
||||
FileLoggerHandlerOption::class,
|
||||
$this->callMethod(
|
||||
$sut,
|
||||
'addFileHandler',
|
||||
['file/path.log', Logger::INFO, 5]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @return void
|
||||
* @covers \D3\LoggerFactory\LoggerFactory::addOxidFileHandler
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LoggerFactory\LoggerFactory::getCombinedOxidAndFileLogger
|
||||
*/
|
||||
public function testGetCombinedOxidAndFileLoggerWithoutOxid(): void
|
||||
public function testAddOxidFileHandler(): void
|
||||
{
|
||||
$sut = $this->getMockBuilder(LoggerFactory::class)
|
||||
->onlyMethods(['applySpecialHandlers'])
|
||||
->getMock();
|
||||
$sut->expects($this->never())->method('applySpecialHandlers')->willReturnArgument(0);
|
||||
$sut = LoggerFactory::create();
|
||||
|
||||
$this->expectException(RuntimeException::class);
|
||||
require_once __DIR__.'/Helpers/classAliases.php';
|
||||
|
||||
$optionsMock = $this->getMockBuilder(Options::class)
|
||||
->onlyMethods(['add'])
|
||||
->getMock();
|
||||
$optionsMock->expects($this->once())->method('add');
|
||||
|
||||
$this->setValue(
|
||||
$sut,
|
||||
'options',
|
||||
$optionsMock
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
OxidLoggerHandlerOption::class,
|
||||
$this->callMethod(
|
||||
$sut,
|
||||
'addOxidFileHandler',
|
||||
['fileNameFixture', Logger::INFO]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @covers \D3\LoggerFactory\LoggerFactory::addMailHandler
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function testAddMailHandler(): void
|
||||
{
|
||||
$sut = LoggerFactory::create();
|
||||
|
||||
$optionsMock = $this->getMockBuilder(Options::class)
|
||||
->onlyMethods(['add'])
|
||||
->getMock();
|
||||
$optionsMock->expects($this->once())->method('add');
|
||||
|
||||
$this->setValue(
|
||||
$sut,
|
||||
'options',
|
||||
$optionsMock
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
MailLoggerHandlerOption::class,
|
||||
$this->callMethod(
|
||||
$sut,
|
||||
'addMailHandler',
|
||||
['toFixture', 'subjectFixture', 'fromFixture', Logger::INFO, true]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @covers \D3\LoggerFactory\LoggerFactory::addOtherHandler
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function testAddOtherHandler(): void
|
||||
{
|
||||
$sut = LoggerFactory::create();
|
||||
|
||||
$optionsMock = $this->getMockBuilder(Options::class)
|
||||
->onlyMethods(['add'])
|
||||
->getMock();
|
||||
$optionsMock->expects($this->once())->method('add');
|
||||
|
||||
$this->setValue(
|
||||
$sut,
|
||||
'options',
|
||||
$optionsMock
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
OtherLoggerHandlerOption::class,
|
||||
$this->callMethod(
|
||||
$sut,
|
||||
'addOtherHandler',
|
||||
[new FirePHPHandler(Logger::ERROR)]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @covers \D3\LoggerFactory\LoggerFactory::addUidProcessor
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function testAddUidProcessor(): void
|
||||
{
|
||||
$sut = LoggerFactory::create();
|
||||
|
||||
$optionsMock = $this->getMockBuilder(Options::class)
|
||||
->onlyMethods(['add'])
|
||||
->getMock();
|
||||
$optionsMock->expects($this->once())->method('add');
|
||||
|
||||
$this->setValue(
|
||||
$sut,
|
||||
'options',
|
||||
$optionsMock
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
UidProcessorOption::class,
|
||||
$this->callMethod(
|
||||
$sut,
|
||||
'addUidProcessor'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @covers \D3\LoggerFactory\LoggerFactory::addSensitiveFilterProcessor
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function testAddSensitiveFilterProcessor(): void
|
||||
{
|
||||
$sut = LoggerFactory::create();
|
||||
|
||||
$optionsMock = $this->getMockBuilder(Options::class)
|
||||
->onlyMethods(['add'])
|
||||
->getMock();
|
||||
$optionsMock->expects($this->once())->method('add');
|
||||
|
||||
$this->setValue(
|
||||
$sut,
|
||||
'options',
|
||||
$optionsMock
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
SensitiveFilterProcessorOption::class,
|
||||
$this->callMethod(
|
||||
$sut,
|
||||
'addSensitiveFilterProcessor'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @covers \D3\LoggerFactory\LoggerFactory::addOtherProcessor
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function testAddOtherProcessor(): void
|
||||
{
|
||||
$sut = LoggerFactory::create();
|
||||
|
||||
$optionsMock = $this->getMockBuilder(Options::class)
|
||||
->onlyMethods(['add'])
|
||||
->getMock();
|
||||
$optionsMock->expects($this->once())->method('add');
|
||||
|
||||
$this->setValue(
|
||||
$sut,
|
||||
'options',
|
||||
$optionsMock
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
OtherProcessorOption::class,
|
||||
$this->callMethod(
|
||||
$sut,
|
||||
'addOtherProcessor',
|
||||
[new TagProcessor(['tag1'])]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @covers \D3\LoggerFactory\LoggerFactory::build
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function testBuild(): void
|
||||
{
|
||||
$loggerBuilderMock = $this->getMockBuilder(LoggerBuilder::class)
|
||||
->onlyMethods(['build'])
|
||||
->getMock();
|
||||
$loggerBuilderMock->expects($this->once())->method('build');
|
||||
|
||||
$sut = $this->getMockBuilder(LoggerFactory::class)
|
||||
->onlyMethods(['getLoggerBuilder'])
|
||||
->getMock();
|
||||
$sut->method('getLoggerBuilder')->willReturn($loggerBuilderMock);
|
||||
|
||||
$this->callMethod(
|
||||
$sut,
|
||||
'getCombinedOxidAndFileLogger',
|
||||
['nameFixture', 'file/path.log', 1, 5]
|
||||
'build',
|
||||
['nameFixture']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LoggerFactory\LoggerFactory::getLoggerBuilder
|
||||
*/
|
||||
public function testGetLoggerBuilder(): void
|
||||
{
|
||||
$sut = LoggerFactory::create();
|
||||
|
||||
$this->assertInstanceOf(
|
||||
LoggerBuilder::class,
|
||||
$this->callMethod(
|
||||
$sut,
|
||||
'getLoggerBuilder',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@ -104,65 +320,23 @@ class LoggerFactoryTest extends ApiTestCase
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LoggerFactory\LoggerFactory::getOxidLogPath
|
||||
*/
|
||||
public function testGetOxidLogPathWithoutOxid(): void
|
||||
public function testGetOxidLogPath(): void
|
||||
{
|
||||
$sut = LoggerFactory::create();
|
||||
|
||||
$this->expectException(RuntimeException::class);
|
||||
|
||||
$this->assertSame(
|
||||
'foo',
|
||||
$this->callMethod(
|
||||
$sut,
|
||||
'getOxidLogPath',
|
||||
['fixture.log']
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LoggerFactory\LoggerFactory::getCombinedOxidAndFileLogger
|
||||
*/
|
||||
public function testGetCombinedOxidAndFileLoggerInOxid(): void
|
||||
{
|
||||
require_once __DIR__.'/Helpers/classAliases.php';
|
||||
$oxidLoggerHandlerMock = $this->getMockBuilder(OxidLoggerHandlerOption::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods(['getOxidLogPath'])
|
||||
->getMock();
|
||||
$oxidLoggerHandlerMock->expects($this->once())->method('getOxidLogPath');
|
||||
|
||||
$sut = $this->getMockBuilder(LoggerFactory::class)
|
||||
->onlyMethods(['applySpecialHandlers'])
|
||||
->onlyMethods(['getOxidLoggerHandlerOption'])
|
||||
->getMock();
|
||||
$sut->expects($this->exactly(2))->method('applySpecialHandlers')->willReturnArgument(0);
|
||||
$sut->method('getOxidLoggerHandlerOption')->willReturn($oxidLoggerHandlerMock);
|
||||
|
||||
$logger = $this->callMethod(
|
||||
$this->callMethod(
|
||||
$sut,
|
||||
'getCombinedOxidAndFileLogger',
|
||||
['nameFixture', 'file/path.log', Logger::INFO, 5]
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(Logger::class, $logger);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LoggerFactory\LoggerFactory::getOxidLogPath
|
||||
*/
|
||||
public function testGetOxidLogPathInOxid(): void
|
||||
{
|
||||
require_once __DIR__.'/Helpers/classAliases.php';
|
||||
|
||||
$sut = LoggerFactory::create();
|
||||
|
||||
$this->assertStringEndsWith(
|
||||
'tests/Helpers/log/fixture.log',
|
||||
$this->callMethod(
|
||||
$sut,
|
||||
'getOxidLogPath',
|
||||
['fixture.log']
|
||||
)
|
||||
'getOxidLogPath',
|
||||
['fixture.log']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
116
tests/Options/FileLoggerHandlerOptionTest.php
Normal file
116
tests/Options/FileLoggerHandlerOptionTest.php
Normal file
@ -0,0 +1,116 @@
|
||||
<?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()
|
||||
);
|
||||
}
|
||||
}
|
73
tests/Options/MailLoggerHandlerOptionTest.php
Normal file
73
tests/Options/MailLoggerHandlerOptionTest.php
Normal file
@ -0,0 +1,73 @@
|
||||
<?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\Options\MailLoggerHandlerOption;
|
||||
use D3\LoggerFactory\tests\AbstractTestCase;
|
||||
use Generator;
|
||||
use Monolog\Formatter\HtmlFormatter;
|
||||
use Monolog\Formatter\LineFormatter;
|
||||
use Monolog\Handler\NativeMailerHandler;
|
||||
use Monolog\Handler\RotatingFileHandler;
|
||||
use Monolog\Handler\StreamHandler;
|
||||
use Monolog\Logger;
|
||||
use ReflectionException;
|
||||
|
||||
/**
|
||||
* @coversNothing
|
||||
*/
|
||||
class MailLoggerHandlerOptionTest extends AbstractTestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LoggerFactory\Options\MailLoggerHandlerOption::__construct
|
||||
* @covers \D3\LoggerFactory\Options\MailLoggerHandlerOption::getHandler
|
||||
* @dataProvider constructDataProvider
|
||||
*/
|
||||
public function testConstruct(bool $isHtml, string $expectedClass): void
|
||||
{
|
||||
$sut = new MailLoggerHandlerOption(
|
||||
'toFixture',
|
||||
'subjectFixture',
|
||||
'fromFixture',
|
||||
Logger::INFO,
|
||||
$isHtml
|
||||
);
|
||||
|
||||
$handler = $this->callMethod(
|
||||
$sut,
|
||||
'getHandler'
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
NativeMailerHandler::class,
|
||||
$handler
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
$expectedClass,
|
||||
$handler->getFormatter()
|
||||
);
|
||||
}
|
||||
|
||||
public static function constructDataProvider(): Generator
|
||||
{
|
||||
yield 'is Html' => [true, HtmlFormatter::class];
|
||||
yield 'is plain' => [false, LineFormatter::class];
|
||||
}
|
||||
}
|
59
tests/Options/OtherLoggerHandlerOptionTest.php
Normal file
59
tests/Options/OtherLoggerHandlerOptionTest.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?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\Options\MailLoggerHandlerOption;
|
||||
use D3\LoggerFactory\Options\OtherLoggerHandlerOption;
|
||||
use D3\LoggerFactory\tests\AbstractTestCase;
|
||||
use D3\LoggerFactory\tests\Helpers\UnknownOption;
|
||||
use Generator;
|
||||
use InvalidArgumentException;
|
||||
use Monolog\Formatter\HtmlFormatter;
|
||||
use Monolog\Formatter\LineFormatter;
|
||||
use Monolog\Handler\FirePHPHandler;
|
||||
use Monolog\Handler\NativeMailerHandler;
|
||||
use Monolog\Handler\RotatingFileHandler;
|
||||
use Monolog\Handler\StreamHandler;
|
||||
use Monolog\Logger;
|
||||
use ReflectionException;
|
||||
|
||||
/**
|
||||
* @coversNothing
|
||||
*/
|
||||
class OtherLoggerHandlerOptionTest extends AbstractTestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LoggerFactory\Options\OtherLoggerHandlerOption::__construct
|
||||
* @covers \D3\LoggerFactory\Options\OtherLoggerHandlerOption::getHandler
|
||||
*/
|
||||
public function testConstruct(): void
|
||||
{
|
||||
$sut = new OtherLoggerHandlerOption(new FirePHPHandler(Logger::INFO));
|
||||
|
||||
$handler = $this->callMethod(
|
||||
$sut,
|
||||
'getHandler'
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
FirePHPHandler::class,
|
||||
$handler
|
||||
);
|
||||
}
|
||||
}
|
48
tests/Options/OtherProcessorOptionTest.php
Normal file
48
tests/Options/OtherProcessorOptionTest.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?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\OtherProcessorOption;
|
||||
use D3\LoggerFactory\tests\AbstractTestCase;
|
||||
use Monolog\Processor\TagProcessor;
|
||||
use ReflectionException;
|
||||
|
||||
/**
|
||||
* @coversNothing
|
||||
*/
|
||||
class OtherProcessorOptionTest extends AbstractTestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LoggerFactory\Options\OtherProcessorOption::__construct
|
||||
* @covers \D3\LoggerFactory\Options\OtherProcessorOption::getProcessor
|
||||
*/
|
||||
public function testConstruct(): void
|
||||
{
|
||||
$sut = new OtherProcessorOption(new TagProcessor(['tag1']));
|
||||
|
||||
$handler = $this->callMethod(
|
||||
$sut,
|
||||
'getProcessor'
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
TagProcessor::class,
|
||||
$handler
|
||||
);
|
||||
}
|
||||
}
|
98
tests/Options/OxidLoggerHandlerOptionTest.php
Normal file
98
tests/Options/OxidLoggerHandlerOptionTest.php
Normal file
@ -0,0 +1,98 @@
|
||||
<?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']
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
51
tests/Options/SensitiveFilterProcessorOptionTest.php
Normal file
51
tests/Options/SensitiveFilterProcessorOptionTest.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?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\SensitiveFilterProcessorOption;
|
||||
use D3\LoggerFactory\SensitiveFilterProcessor;
|
||||
use D3\LoggerFactory\tests\AbstractTestCase;
|
||||
use ReflectionException;
|
||||
|
||||
/**
|
||||
* @coversNothing
|
||||
*/
|
||||
class SensitiveFilterProcessorOptionTest extends AbstractTestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LoggerFactory\Options\SensitiveFilterProcessorOption::__construct
|
||||
* @covers \D3\LoggerFactory\Options\SensitiveFilterProcessorOption::getProcessor
|
||||
*/
|
||||
public function testConstruct(): void
|
||||
{
|
||||
$sut = new SensitiveFilterProcessorOption(
|
||||
['foo', 'bar', 'baz'],
|
||||
'replacementFixture'
|
||||
);
|
||||
|
||||
$handler = $this->callMethod(
|
||||
$sut,
|
||||
'getProcessor'
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
SensitiveFilterProcessor::class,
|
||||
$handler
|
||||
);
|
||||
}
|
||||
}
|
48
tests/Options/UidProcessorOptionTest.php
Normal file
48
tests/Options/UidProcessorOptionTest.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?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\UidProcessorOption;
|
||||
use D3\LoggerFactory\tests\AbstractTestCase;
|
||||
use Monolog\Processor\UidProcessor;
|
||||
use ReflectionException;
|
||||
|
||||
/**
|
||||
* @coversNothing
|
||||
*/
|
||||
class UidProcessorOptionTest extends AbstractTestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LoggerFactory\Options\UidProcessorOption::__construct
|
||||
* @covers \D3\LoggerFactory\Options\UidProcessorOption::getProcessor
|
||||
*/
|
||||
public function testConstruct(): void
|
||||
{
|
||||
$sut = new UidProcessorOption();
|
||||
|
||||
$handler = $this->callMethod(
|
||||
$sut,
|
||||
'getProcessor'
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
UidProcessor::class,
|
||||
$handler
|
||||
);
|
||||
}
|
||||
}
|
75
tests/OptionsTest.php
Normal file
75
tests/OptionsTest.php
Normal file
@ -0,0 +1,75 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\LoggerFactory\tests;
|
||||
|
||||
use D3\LoggerFactory\Options;
|
||||
use D3\LoggerFactory\Options\FileLoggerHandlerOption;
|
||||
use D3\LoggerFactory\Options\OptionInterface;
|
||||
use D3\LoggerFactory\Options\UidProcessorOption;
|
||||
use D3\LoggerFactory\tests\Helpers\UnknownOption;
|
||||
use Monolog\Logger;
|
||||
use ReflectionException;
|
||||
|
||||
/**
|
||||
* @coversNothing
|
||||
*/
|
||||
class OptionsTest extends AbstractTestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LoggerFactory\Options::add
|
||||
*/
|
||||
public function testAdd(): void
|
||||
{
|
||||
$sut = new Options();
|
||||
$sut->add(new FileLoggerHandlerOption('file/path.log', Logger::INFO, 5));
|
||||
$sut->add(new UidProcessorOption());
|
||||
$sut->add(new UnknownOption());
|
||||
|
||||
$this->assertCount(
|
||||
3,
|
||||
$this->getValue(
|
||||
$sut,
|
||||
'options'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LoggerFactory\Options::getAll
|
||||
*/
|
||||
public function testGetAll(): void
|
||||
{
|
||||
$sut = new Options();
|
||||
$sut->add(new FileLoggerHandlerOption('file/path.log', Logger::INFO, 5));
|
||||
$sut->add(new UidProcessorOption());
|
||||
$sut->add(new UnknownOption());
|
||||
|
||||
$all = $this->callMethod(
|
||||
$sut,
|
||||
'getAll',
|
||||
);
|
||||
|
||||
$this->assertCount(3, $all);
|
||||
$this->assertIsArray($all);
|
||||
$this->assertContainsOnlyInstancesOf(OptionInterface::class, $all);
|
||||
}
|
||||
}
|
11
tests/README.md
Normal file
11
tests/README.md
Normal file
@ -0,0 +1,11 @@
|
||||
# Installation
|
||||
|
||||
```
|
||||
composer create-project -s dev --prefer-source [--repository '{"type": "vcs", "url": "repository url"}'] d3/logger-factory .
|
||||
```
|
||||
|
||||
# Run tests
|
||||
|
||||
```
|
||||
./vendor/bin/phpunit [--no-coverage] [--coverage-html=cov]
|
||||
```
|
@ -13,6 +13,8 @@
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\LoggerFactory\tests;
|
||||
|
||||
use D3\LoggerFactory\SensitiveFilterProcessor;
|
||||
@ -22,7 +24,7 @@ use ReflectionException;
|
||||
/**
|
||||
* @coversNothing
|
||||
*/
|
||||
class SensitiveFilterProcessorTest extends ApiTestCase
|
||||
class SensitiveFilterProcessorTest extends AbstractTestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
|
Reference in New Issue
Block a user