add tests for RequestFactory class

This commit is contained in:
Daniel Seifert 2023-01-04 23:08:05 +01:00
parent e4699d4d19
commit e4393803bf
Signed by: DanielS
GPG Key ID: 6A513E13AEE66170
3 changed files with 97 additions and 3 deletions

View File

@ -18,17 +18,25 @@ namespace D3\Linkmobility4OXID\Application\Model;
use D3\LinkmobilityClient\Request\RequestInterface;
use D3\LinkmobilityClient\SMS\SmsRequestInterface;
use D3\LinkmobilityClient\ValueObject\Sender;
use D3\TestingTools\Production\IsMockable;
class RequestFactory extends \D3\LinkmobilityClient\SMS\RequestFactory
{
use IsMockable;
public function getSmsRequest(): SmsRequestInterface
{
$configuration = oxNew(Configuration::class);
/** @var Configuration $configuration */
$configuration = d3GetOxidDIC()->get(Configuration::class);
$request = parent::getSmsRequest();
/** parent call */
$request = $this->d3CallMockableFunction([\D3\LinkmobilityClient\SMS\RequestFactory::class, 'getSmsRequest']);
d3GetOxidDIC()->setParameter(Sender::class.'.args.number', $configuration->getSmsSenderNumber());
d3GetOxidDIC()->setParameter(Sender::class.'.args.iso2countrycode', $configuration->getSmsSenderCountry());
$request->setTestMode($configuration->getTestMode())
->setSenderAddress(
oxNew(Sender::class, $configuration->getSmsSenderNumber(), $configuration->getSmsSenderCountry())
d3GetOxidDIC()->get(Sender::class)
)
->setSenderAddressType(RequestInterface::SENDERADDRESSTYPE_INTERNATIONAL);

View File

@ -10,6 +10,8 @@
parameters:
D3\LinkmobilityClient\ValueObject\Recipient.args.number:
D3\LinkmobilityClient\ValueObject\Recipient.args.iso2countrycode:
D3\LinkmobilityClient\ValueObject\Sender.args.number:
D3\LinkmobilityClient\ValueObject\Sender.args.iso2countrycode:
services:
_defaults:
@ -32,6 +34,15 @@ services:
- '%D3\LinkmobilityClient\ValueObject\Recipient.args.number%'
- '%D3\LinkmobilityClient\ValueObject\Recipient.args.iso2countrycode%'
D3\LinkmobilityClient\ValueObject\Sender:
class: D3\LinkmobilityClient\ValueObject\Sender
factory: 'oxNew'
shared: false
arguments:
- D3\LinkmobilityClient\ValueObject\Sender
- '%D3\LinkmobilityClient\ValueObject\Sender.args.number%'
- '%D3\LinkmobilityClient\ValueObject\Sender.args.iso2countrycode%'
D3\LinkmobilityClient\Exceptions\RecipientException:
class: D3\LinkmobilityClient\Exceptions\RecipientException
factory: 'oxNew'

View File

@ -0,0 +1,75 @@
<?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\RequestFactory;
use D3\Linkmobility4OXID\tests\unit\LMUnitTestCase;
use D3\LinkmobilityClient\SMS\SmsRequestInterface;
use D3\LinkmobilityClient\SMS\TextRequest;
use D3\LinkmobilityClient\ValueObject\Sender;
use D3\TestingTools\Development\CanAccessRestricted;
use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException;
class RequestFactoryTest extends LMUnitTestCase
{
use CanAccessRestricted;
/**
* @test
* @return void
* @throws ReflectionException
* @covers \D3\Linkmobility4OXID\Application\Model\RequestFactory::getSmsRequest
*/
public function canGetSmsRequest()
{
/** @var Configuration|MockObject $configurationMock */
$configurationMock = $this->getMockBuilder(Configuration::class)
->onlyMethods(['getTestMode', 'getSmsSenderNumber', 'getSmsSenderCountry'])
->getMock();
$configurationMock->expects($this->once())->method('getTestMode')->willReturn(true);
$configurationMock->expects($this->once())->method('getSmsSenderNumber')->willReturn('01512 3456789');
$configurationMock->expects($this->once())->method('getSmsSenderCountry')->willReturn('DE');
d3GetOxidDIC()->set(Configuration::class, $configurationMock);
/** @var Sender|MockObject $senderMock */
$senderMock = $this->getMockBuilder(Sender::class)
->disableOriginalConstructor()
->getMock();
d3GetOxidDIC()->set(Sender::class, $senderMock);
/** @var TextRequest|MockObject $textRequestMock */
$textRequestMock = $this->getMockBuilder(TextRequest::class)
->disableOriginalConstructor()
->getMock();
/** @var RequestFactory|MockObject $sut */
$sut = $this->getMockBuilder(RequestFactory::class)
->disableOriginalConstructor()
->onlyMethods(['d3CallMockableFunction'])
->getMock();
$sut->method('d3CallMockableFunction')->willReturn($textRequestMock);
$this->assertInstanceOf(
SmsRequestInterface::class,
$this->callMethod(
$sut,
'getSmsRequest'
)
);
}
}