add tests
This commit is contained in:
parent
468bcb1c3d
commit
507d2b2b23
@ -33,10 +33,10 @@ trait OxidLoggerTrait
|
|||||||
|
|
||||||
public function getOxidLogPath(string $fileName): string
|
public function getOxidLogPath(string $fileName): string
|
||||||
{
|
{
|
||||||
if (!defined(OX_BASE_PATH)) {
|
if (!class_exists(Registry::class)) {
|
||||||
throw new RuntimeException(__METHOD__.' can executed in OXID eShop installations only');
|
throw new RuntimeException(__METHOD__.' can executed in OXID eShop installations only');
|
||||||
}
|
}
|
||||||
|
|
||||||
return OX_BASE_PATH . 'log' . DIRECTORY_SEPARATOR . $fileName;
|
return OX_BASE_PATH . '/log' . DIRECTORY_SEPARATOR . $fileName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
108
tests/Apps/OxidLoggerTestTrait.php
Normal file
108
tests/Apps/OxidLoggerTestTrait.php
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
<?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 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::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']
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -18,6 +18,7 @@ declare(strict_types=1);
|
|||||||
namespace D3\GuzzleFactory\tests;
|
namespace D3\GuzzleFactory\tests;
|
||||||
|
|
||||||
use D3\GuzzleFactory\GuzzleFactory;
|
use D3\GuzzleFactory\GuzzleFactory;
|
||||||
|
use D3\GuzzleFactory\tests\Apps\OxidLoggerTestTrait;
|
||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
use GuzzleHttp\HandlerStack;
|
use GuzzleHttp\HandlerStack;
|
||||||
use Monolog\Logger;
|
use Monolog\Logger;
|
||||||
@ -31,6 +32,7 @@ class GuzzleFactoryTest extends ApiTestCase
|
|||||||
use HeaderTestTrait;
|
use HeaderTestTrait;
|
||||||
use LoggerTestTrait;
|
use LoggerTestTrait;
|
||||||
use MessageFormatterTestTrait;
|
use MessageFormatterTestTrait;
|
||||||
|
use OxidLoggerTestTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
|
Loading…
x
Reference in New Issue
Block a user