linkmobility-php-client/Tests/ValueObject/SmsBinaryMessageTest.php

218 lignes
7.0 KiB
PHP
Brut Vue normale Historique

2022-07-11 15:06:18 +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 15:06:18 +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 15:06:18 +02:00
*/
2022-07-13 10:41:23 +02:00
declare(strict_types=1);
2022-07-11 15:06:18 +02:00
namespace D3\LinkmobilityClient\Tests\ValueObject;
use D3\LinkmobilityClient\ValueObject\SmsBinaryMessage;
use Phlib\SmsLength\Exception\InvalidArgumentException;
2022-07-11 15:06:18 +02:00
use Phlib\SmsLength\SmsLength;
use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException;
2022-07-21 14:07:10 +02:00
class SmsBinaryMessageTest extends SmsMessageAbstractTest
2022-07-11 15:06:18 +02:00
{
/** @var SmsBinaryMessage */
public $message;
private $messageFixture = "testMessage";
/**
* @return void
*/
2022-07-13 10:41:23 +02:00
public function setUp(): void
2022-07-11 15:06:18 +02:00
{
parent::setUp();
2022-07-13 10:41:23 +02:00
$this->message = new SmsBinaryMessage($this->messageFixture);
2022-07-11 15:06:18 +02:00
}
/**
* @test
* @return void
* @throws ReflectionException
* @covers \D3\LinkmobilityClient\ValueObject\SmsBinaryMessage::__construct
2022-07-21 14:07:10 +02:00
* @covers \D3\LinkmobilityClient\ValueObject\SmsMessageAbstract::__construct
2022-07-11 15:06:18 +02:00
*/
public function testConstructValid()
{
/** @var SmsLength|MockObject $smsLengthMock */
$smsLengthMock = $this->getMockBuilder(SmsLength::class)
->disableOriginalConstructor()
->onlyMethods(['validate'])
->getMock();
$smsLengthMock->expects($this->atLeastOnce())->method('validate')->willReturn(true);
/** @var SmsBinaryMessage|MockObject $message */
$message = $this->getMockBuilder(SmsBinaryMessage::class)
->onlyMethods(['getSmsLength'])
->disableOriginalConstructor()
->getMock();
$message->method('getSmsLength')->willReturn($smsLengthMock);
$message->__construct($this->messageFixture);
$this->assertSame(
$this->messageFixture,
$this->callMethod(
$message,
'get'
)
);
}
/**
* @test
*
* @param $binaryMessage
* @param $valid
* @param $expectedException
*
* @throws ReflectionException
* @dataProvider constructInvalidDataProvider
* @covers \D3\LinkmobilityClient\ValueObject\SmsBinaryMessage::__construct
2022-07-21 14:07:10 +02:00
* @covers \D3\LinkmobilityClient\ValueObject\SmsMessageAbstract::__construct
2022-07-11 15:06:18 +02:00
*/
public function testConstructInvalid($binaryMessage, $valid, $expectedException)
{
/** @var SmsLength|MockObject $smsLengthMock */
$smsLengthMock = $this->getMockBuilder(SmsLength::class)
->disableOriginalConstructor()
->onlyMethods(['validate'])
->getMock();
if ($valid) {
2022-07-13 10:41:23 +02:00
$smsLengthMock->expects($this->never())->method('validate')->willReturn(true);
2022-07-11 15:06:18 +02:00
} else {
$smsLengthMock->expects($this->atLeastOnce())->method('validate')->willThrowException(new InvalidArgumentException());
2022-07-11 15:06:18 +02:00
}
/** @var SmsBinaryMessage|MockObject $message */
$message = $this->getMockBuilder(SmsBinaryMessage::class)
->onlyMethods(['getSmsLength'])
->disableOriginalConstructor()
->getMock();
$message->method('getSmsLength')->willReturn($smsLengthMock);
$this->expectException($expectedException);
$message->__construct($binaryMessage);
$this->assertSame(
$message,
$this->callMethod(
$message,
'get'
)
);
}
/**
* @test
2022-07-11 15:06:18 +02:00
* @throws ReflectionException
* @covers \D3\LinkmobilityClient\ValueObject\SmsBinaryMessage::chunkCount
2022-07-21 14:07:10 +02:00
* @covers \D3\LinkmobilityClient\ValueObject\SmsMessageAbstract::chunkCount
2022-07-11 15:06:18 +02:00
*/
public function testGetChunkCount()
{
$expected = 2;
/** @var SmsLength|MockObject $smsLengthMock */
$smsLengthMock = $this->getMockBuilder(SmsLength::class)
->onlyMethods(['getMessageCount', 'validate'])
->disableOriginalConstructor()
->getMock();
$smsLengthMock->expects($this->once())->method('getMessageCount')->willReturn($expected);
$smsLengthMock->method('validate')->willReturn(true);
/** @var SmsBinaryMessage|MockObject $message */
$message = $this->getMockBuilder(SmsBinaryMessage::class)
2022-07-21 14:07:10 +02:00
->onlyMethods(['getSmsLength'])
->disableOriginalConstructor()
->getMock();
2022-07-11 15:06:18 +02:00
$message->method('getSmsLength')->willReturn($smsLengthMock);
$this->assertSame(
$expected,
$this->callMethod(
$message,
'chunkCount'
)
);
}
/**
* @test
2022-07-11 15:06:18 +02:00
* @throws ReflectionException
* @covers \D3\LinkmobilityClient\ValueObject\SmsBinaryMessage::length
2022-07-21 14:07:10 +02:00
* @covers \D3\LinkmobilityClient\ValueObject\SmsMessageAbstract::length
2022-07-11 15:06:18 +02:00
*/
public function testGetSize()
{
$expected = 55;
/** @var SmsLength|MockObject $smsLengthMock */
$smsLengthMock = $this->getMockBuilder(SmsLength::class)
->onlyMethods(['getSize', 'validate'])
->disableOriginalConstructor()
->getMock();
$smsLengthMock->expects($this->once())->method('getSize')->willReturn($expected);
$smsLengthMock->method('validate')->willReturn(true);
/** @var SmsBinaryMessage|MockObject $message */
$message = $this->getMockBuilder(SmsBinaryMessage::class)
->onlyMethods(['getSmsLength'])
->disableOriginalConstructor()
->getMock();
$message->method('getSmsLength')->willReturn($smsLengthMock);
$this->assertSame(
$expected,
$this->callMethod(
$message,
'length'
)
);
}
/**
* @test
2022-07-11 15:06:18 +02:00
* @throws ReflectionException
* @covers \D3\LinkmobilityClient\ValueObject\SmsBinaryMessage::getMessageContent
* @covers \D3\LinkmobilityClient\ValueObject\SmsMessageAbstract::getMessageContent
2022-07-11 15:06:18 +02:00
*/
public function testGetMessageContent()
{
/** @var SmsLength|MockObject $smsLengthMock */
$smsLengthMock = $this->getMockBuilder(SmsLength::class)
->onlyMethods(['validate'])
->disableOriginalConstructor()
->getMock();
$smsLengthMock->method('validate')->willReturn(true);
/** @var SmsBinaryMessage|MockObject $message */
$message = $this->getMockBuilder(SmsBinaryMessage::class)
->onlyMethods(['getSmsLength'])
->disableOriginalConstructor()
->getMock();
$message->method('getSmsLength')->willReturn($smsLengthMock);
$message->__construct($this->messageFixture);
$this->assertSame(
['dGVzdE1lc3NhZ2U='], // binary content
$this->callMethod(
$message,
'getMessageContent'
)
);
}
2022-07-13 10:41:23 +02:00
}