add tests for MessageClient class

This commit is contained in:
Daniel Seifert 2023-01-06 23:42:17 +01:00
parent 339af80a2d
commit f7418e06b0
Signed by: DanielS
GPG Key ID: 6A513E13AEE66170
4 changed files with 103 additions and 4 deletions

View File

@ -17,7 +17,7 @@ namespace D3\Linkmobility4OXID\Application\Model;
use D3\LinkmobilityClient\Client;
use D3\LinkmobilityClient\LoggerHandler;
use OxidEsales\Eshop\Core\Registry;
use Psr\Log\LoggerInterface;
class MessageClient
{
@ -26,8 +26,18 @@ class MessageClient
*/
public function getClient(): Client
{
$client = oxNew(Client::class, oxNew(Configuration::class)->getApiToken());
LoggerHandler::getInstance()->setLogger(Registry::getLogger());
/** @var Configuration $configuration */
$configuration = d3GetOxidDIC()->get(Configuration::class);
d3GetOxidDIC()->setParameter(Client::class.'.args.accesstoken', $configuration->getApiToken());
/** @var Client $client */
$client = d3GetOxidDIC()->get(Client::class);
/** @var LoggerHandler $loggerHandler */
$loggerHandler = d3GetOxidDIC()->get(LoggerHandler::class);
/** @var LoggerInterface $logger */
$logger = d3GetOxidDIC()->get('d3ox.linkmobility.'.LoggerInterface::class);
$loggerHandler->setLogger($logger);
return $client;
}

View File

@ -8,6 +8,7 @@
# @link https://www.oxidmodule.com
parameters:
D3\LinkmobilityClient\Client.args.accesstoken:
D3\LinkmobilityClient\ValueObject\Recipient.args.number:
D3\LinkmobilityClient\ValueObject\Recipient.args.iso2countrycode:
D3\LinkmobilityClient\ValueObject\Sender.args.number:
@ -25,6 +26,14 @@ services:
- 'getInstance'
shared: true
D3\LinkmobilityClient\Client:
class: D3\LinkmobilityClient\Client
factory: 'oxNew'
shared: false
arguments:
- D3\LinkmobilityClient\Client
- '%D3\LinkmobilityClient\Client.args.accesstoken%'
D3\LinkmobilityClient\ValueObject\Recipient:
class: D3\LinkmobilityClient\ValueObject\Recipient
factory: 'oxNew'

View File

@ -16,6 +16,14 @@ services:
autowire: false
public: true
# config
d3ox.linkmobility.OxidEsales\Eshop\Core\Config:
class: 'OxidEsales\Eshop\Core\Config'
factory:
- 'OxidEsales\Eshop\Core\Registry'
- 'getConfig'
shared: true
# lang
d3ox.linkmobility.OxidEsales\Eshop\Core\Language:
class: 'OxidEsales\Eshop\Core\Session'
@ -56,4 +64,11 @@ services:
factory: 'oxNew'
arguments:
- 'OxidEsales\Eshop\Application\Model\Country'
shared: false
shared: false
d3ox.linkmobility.Psr\Log\LoggerInterface:
class: Psr\Log\LoggerInterface
factory:
- 'OxidEsales\Eshop\Core\Registry'
- 'getLogger'
shared: true

View File

@ -0,0 +1,65 @@
<?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\Linkmobility4OXID\tests\unit\Application\Model;
use D3\Linkmobility4OXID\Application\Model\Configuration;
use D3\Linkmobility4OXID\Application\Model\MessageClient;
use D3\Linkmobility4OXID\tests\unit\LMUnitTestCase;
use D3\LinkmobilityClient\Client;
use D3\LinkmobilityClient\LoggerHandler;
use D3\TestingTools\Development\CanAccessRestricted;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use ReflectionException;
class MessageClientTest extends LMUnitTestCase
{
use CanAccessRestricted;
/**
* @test
* @return void
* @throws ReflectionException
* @covers \D3\Linkmobility4OXID\Application\Model\MessageClient::getClient
*/
public function canGetClient()
{
/** @var Configuration|MockObject $configurationMock */
$configurationMock = $this->getMockBuilder(Configuration::class)
->onlyMethods(['getApiToken'])
->getMock();
$configurationMock->method('getApiToken')->willReturn('apiTokenFixture');
d3GetOxidDIC()->set(Configuration::class, $configurationMock);
/** @var MessageClient $sut */
$sut = oxNew(MessageClient::class);
$this->assertInstanceOf(
Client::class,
$this->callMethod(
$sut,
'getClient'
)
);
/** @var LoggerHandler $loggerHandler */
$loggerHandler = d3GetOxidDIC()->get(LoggerHandler::class);
$this->assertInstanceOf(
LoggerInterface::class,
$loggerHandler->getLogger()
);
}
}