linkmobility-php-client/Tests/SMS/RequestFactoryTest.php

134 lines
3.7 KiB
PHP
Raw Normal View History

2022-07-11 23:30:44 +02:00
<?php
/**
2022-07-13 10:50:45 +02:00
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* https://www.d3data.de
2022-07-11 23:30:44 +02:00
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
2022-07-13 10:50:45 +02:00
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
* @link https://www.oxidmodule.com
2022-07-11 23:30:44 +02:00
*/
2022-07-13 10:41:23 +02:00
declare(strict_types=1);
2022-07-11 23:30:44 +02:00
namespace D3\LinkmobilityClient\Tests\SMS;
use D3\LinkmobilityClient\Client;
use D3\LinkmobilityClient\SMS\BinaryRequest;
use D3\LinkmobilityClient\SMS\RequestFactory;
use D3\LinkmobilityClient\SMS\TextRequest;
use D3\LinkmobilityClient\Tests\ApiTestCase;
use Phlib\SmsLength\SmsLength;
use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException;
class RequestFactoryTest extends ApiTestCase
{
/**
* @test
* @return void
* @throws ReflectionException
*/
public function testConstruct()
{
$message = 'fixtureMessage';
/** @var Client|MockObject $clientMock */
$clientMock = $this->getMockBuilder(Client::class)
->disableOriginalConstructor()
->getMock();
$requestFactory = new RequestFactory($message, $clientMock);
$this->assertSame(
$message,
$this->getValue($requestFactory, 'message')
);
$this->assertSame(
$clientMock,
$this->getValue($requestFactory, 'client')
);
}
/**
* @test
* @param $encoding
* @param $expectedClass
* @return void
* @throws ReflectionException
* @dataProvider getTextSmsRequestDataProvider
*/
public function testGetTextSmsRequest($encoding, $expectedClass)
{
$message = 'fixtureMessage';
/** @var Client|MockObject $clientMock */
$clientMock = $this->getMockBuilder(Client::class)
->disableOriginalConstructor()
->getMock();
/** @var SmsLength|MockObject $smsLengthMock */
$smsLengthMock = $this->getMockBuilder(SmsLength::class)
->onlyMethods(['getEncoding'])
->disableOriginalConstructor()
->getMock();
$smsLengthMock->method('getEncoding')->willReturn($encoding);
/** @var RequestFactory|MockObject $requestFactoryMock */
$requestFactoryMock = $this->getMockBuilder(RequestFactory::class)
->setConstructorArgs([$message, $clientMock])
->onlyMethods(['getSmsLength'])
->getMock();
$requestFactoryMock->method('getSmsLength')->willReturn($smsLengthMock);
$this->assertInstanceOf(
$expectedClass,
$this->callMethod(
$requestFactoryMock,
'getSmsRequest'
)
);
}
/**
* @return array[]
*/
public function getTextSmsRequestDataProvider(): array
{
return [
'binary' => [RequestFactory::GSM_UCS2, BinaryRequest::class],
'ascii' => [RequestFactory::GSM_7BIT, TextRequest::class]
];
}
/**
* @test
* @return void
* @throws ReflectionException
*/
public function testGetSmsLengthInstance()
{
$message = 'fixtureMessage';
/** @var Client|MockObject $clientMock */
$clientMock = $this->getMockBuilder(Client::class)
->disableOriginalConstructor()
->getMock();
/** @var RequestFactory|MockObject $requestFactoryMock */
$requestFactoryMock = $this->getMockBuilder(RequestFactory::class)
->setConstructorArgs([$message, $clientMock])
->getMock();
$this->assertInstanceOf(
SmsLength::class,
$this->callMethod(
$requestFactoryMock,
'getSmsLength'
)
);
}
2022-07-13 10:41:23 +02:00
}