linkmobility-php-client/Tests/ALoggerHandlerTest.php

105 lines
2.5 KiB
PHP
Raw Permalink Normal View History

2022-07-14 11:47:45 +02:00
<?php
/**
* 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 <support@shopmodule.com>
* @link https://www.oxidmodule.com
*/
declare(strict_types=1);
namespace D3\LinkmobilityClient\Tests;
use D3\LinkmobilityClient\LoggerHandler;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\AbstractLogger;
use Psr\Log\LoggerInterface;
use ReflectionException;
class ALoggerHandlerTest extends ApiTestCase
2022-07-14 11:47:45 +02:00
{
/** tests must run as first, because of singleton, which must not initialized before */
2022-07-14 11:47:45 +02:00
/** @var LoggerHandler */
public $loggerHandler;
/**
* @return void
*/
public function setUp(): void
{
parent::setUp();
$this->loggerHandler = new LoggerHandler();
}
/**
* @return void
*/
public function tearDown(): void
{
parent::tearDown();
unset($this->loggerHandler);
}
/**
* @test
* @return void
* @covers \D3\LinkmobilityClient\LoggerHandler::getInstance
*/
public function testGetInstance()
{
// not existing instance
$this->assertInstanceOf(
LoggerHandler::class,
LoggerHandler::getInstance()
);
// existing instance
$this->assertInstanceOf(
LoggerHandler::class,
LoggerHandler::getInstance()
);
}
2022-07-14 11:47:45 +02:00
/**
* @test
* @throws ReflectionException
* @covers \D3\LinkmobilityClient\LoggerHandler::__construct
2022-07-14 11:47:45 +02:00
*/
public function testConstruct()
{
$this->assertInstanceOf(
LoggerInterface::class,
$this->callMethod($this->loggerHandler, 'getLogger')
);
}
/**
* @test
* @return void
* @throws ReflectionException
* @covers \D3\LinkmobilityClient\LoggerHandler::setLogger
* @covers \D3\LinkmobilityClient\LoggerHandler::getLogger
2022-07-14 11:47:45 +02:00
*/
public function testLogger()
{
/** @var LoggerInterface|MockObject $loggerMock */
$loggerMock = $this->getMockBuilder(AbstractLogger::class)
->onlyMethods(['debug', 'error', 'log'])
->getMock();
2022-07-14 12:07:18 +02:00
$this->callMethod($this->loggerHandler, 'setLogger', [ $loggerMock]);
2022-07-14 11:47:45 +02:00
$this->assertSame(
$loggerMock,
2022-07-14 12:07:18 +02:00
$this->callMethod($this->loggerHandler, 'getLogger')
2022-07-14 11:47:45 +02:00
);
}
}