align tests

This commit is contained in:
Daniel Seifert 2025-05-16 11:06:45 +02:00
parent dc7cf4e116
commit 16e88e55cd
4 changed files with 5 additions and 228 deletions

View File

@ -24,7 +24,8 @@
"require-dev": {
"phpunit/phpunit": "^10.5",
"friendsofphp/php-cs-fixer": "^3.65",
"phpstan/phpstan": "^2.0"
"phpstan/phpstan": "^2.0",
"monolog/monolog": "^3.9"
},
"autoload": {
"psr-4": {
@ -37,10 +38,12 @@
}
},
"scripts": {
"test": "./vendor/bin/phpunit --no-coverage",
"test": "XDEBUG_MODE=off ./vendor/bin/phpunit --no-coverage",
"test-coverage": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --coverage-html=coverage",
"check-style": "./vendor/bin/php-cs-fixer fix --verbose --dry-run",
"fix-style": "./vendor/bin/php-cs-fixer fix --verbose",
"check-code": "./vendor/bin/phpstan analyse -c phpstan.neon --no-progress --ansi"
}
}

View File

@ -1,143 +0,0 @@
<?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\GuzzleFactory\tests\Apps;
use D3\GuzzleFactory\GuzzleFactory;
use D3\LoggerFactory\LoggerFactory;
use Monolog\Logger;
use ReflectionException;
use RuntimeException;
trait OxidLoggerTestTrait
{
/**
* @test
* @return void
* @throws ReflectionException
* @covers \D3\GuzzleFactory\GuzzleFactory::addOxidLogger
*/
public function testAddOxidLoggerWithoutOxid(): void
{
$sut = GuzzleFactory::create();
$this->expectException(RuntimeException::class);
$this->callMethod(
$sut,
'addOxidLogger',
);
}
/**
* @test
* @return void
* @throws ReflectionException
* @covers \D3\GuzzleFactory\GuzzleFactory::getOxidLogPath
*/
public function testGetOxidLogPathWithoutOxid(): void
{
$sut = GuzzleFactory::create();
$this->expectException(RuntimeException::class);
$this->assertSame(
'foo',
$this->callMethod(
$sut,
'getOxidLogPath',
['fixture.log']
)
);
}
/**
* @test
* @return void
* @throws ReflectionException
* @covers \D3\GuzzleFactory\GuzzleFactory::addOxidLogger
*/
public function testAddOxidLoggerInOxid(): void
{
require_once __DIR__.'/../Helpers/classAliases.php';
$sut = GuzzleFactory::create();
$this->callMethod(
$sut,
'addOxidLogger',
);
$loggers = $this->getValue($sut, 'loggers');
$this->assertArrayHasKey('oxid', $loggers);
$this->assertInstanceOf(Logger::class, $loggers['oxid']);
}
/**
* @test
* @return void
* @throws ReflectionException
* @covers \D3\GuzzleFactory\GuzzleFactory::addCombinedOxidAndFileLogger
*/
public function testAddCombinedOxidAndFileLogger(): void
{
require_once __DIR__.'/../Helpers/classAliases.php';
$loggerFactory = $this->getMockBuilder(LoggerFactory::class)
->onlyMethods(['getCombinedOxidAndFileLogger'])
->getMock();
$loggerFactory->expects($this->once())->method('getCombinedOxidAndFileLogger');
$sut = $this->getMockBuilder(GuzzleFactory::class)
->onlyMethods(['getLoggerFactory'])
->getMock();
$sut->method('getLoggerFactory')->willReturn($loggerFactory);
$this->setValue($sut, 'loggers', ['oxid' => 1]);
$this->callMethod(
$sut,
'addCombinedOxidAndFileLogger',
['nameFixture', 'file/path.log', 1, 5]
);
$loggers = $this->getValue($sut, 'loggers');
$this->assertArrayHasKey('nameFixture', $loggers);
$this->assertArrayNotHasKey('oxid', $loggers);
$this->assertInstanceOf(Logger::class, $loggers['nameFixture']);
}
/**
* @test
* @return void
* @throws ReflectionException
* @covers \D3\GuzzleFactory\GuzzleFactory::getOxidLogPath
*/
public function testGetOxidLogPathInOxid(): void
{
require_once __DIR__.'/../Helpers/classAliases.php';
$sut = GuzzleFactory::create();
$this->assertStringEndsWith(
'tests/Helpers/log/fixture.log',
$this->callMethod(
$sut,
'getOxidLogPath',
['fixture.log']
)
);
}
}

View File

@ -32,7 +32,6 @@ class GuzzleFactoryTest extends ApiTestCase
use HeaderTestTrait;
use LoggerTestTrait;
use MessageFormatterTestTrait;
use OxidLoggerTestTrait;
/**
* @test

View File

@ -24,88 +24,6 @@ use ReflectionException;
trait LoggerTestTrait
{
/**
* @test
* @return void
* @throws ReflectionException
* @covers \D3\GuzzleFactory\GuzzleFactory::getLoggerFactory
*/
public function testGetLoggerFactory(): void
{
$sut = GuzzleFactory::create();
$this->assertInstanceOf(
LoggerFactory::class,
$this->callMethod(
$sut,
'getLoggerFactory',
)
);
}
/**
* @test
* @throws ReflectionException
* @covers \D3\GuzzleFactory\GuzzleFactory::addFileLogger
* @dataProvider addFileLoggerDataProvider
*/
public function testAddFileLogger(int $logLevel, ?int $maxFiles): void
{
$logger = $this->getMockBuilder(Logger::class)
->disableOriginalConstructor()
->getMock();
$loggerFactory = $this->getMockBuilder(LoggerFactory::class)
->onlyMethods(['getFileLogger'])
->getMock();
$loggerFactory->expects($this->once())->method('getFileLogger')->willReturn($logger);
$sut = $this->getMockBuilder(GuzzleFactory::class)
->onlyMethods(['getLoggerFactory'])
->getMock();
$sut->method("getLoggerFactory")->willReturn($loggerFactory);
$this->callMethod(
$sut,
'addFileLogger',
['nameFixture', 'file/path.log', $logLevel, $maxFiles]
);
$loggers = $this->getValue($sut, 'loggers');
$this->assertArrayHasKey('nameFixture', $loggers);
$this->assertInstanceOf(Logger::class, $loggers['nameFixture']);
}
public static function addFileLoggerDataProvider(): Generator
{
yield [Logger::INFO, null];
}
/**
* @test
* @return void
* @throws ReflectionException
* @covers \D3\GuzzleFactory\GuzzleFactory::getFileLoggerStreamHandler
*/
public function testGetFileLoggerStreamHandler(): void
{
$loggerFactory = $this->getMockBuilder(LoggerFactory::class)
->onlyMethods(['getFileLoggerStreamHandler'])
->getMock();
$loggerFactory->expects($this->once())->method('getFileLoggerStreamHandler');
$sut = $this->getMockBuilder(GuzzleFactory::class)
->onlyMethods(['getLoggerFactory'])
->getMock();
$sut->method("getLoggerFactory")->willReturn($loggerFactory);
$this->callMethod(
$sut,
'getFileLoggerStreamHandler',
['file/path.log', Logger::ERROR, 2]
);
}
/**
* @test
* @return void