improve code
This commit is contained in:
parent
b33b6081ad
commit
fed8040fcb
@ -89,13 +89,10 @@ abstract class AbstractRequest extends ApiTestCase
|
||||
$requestMock->expects($this->atLeastOnce())->method('setMessage')->with($this->equalTo($messageMock))->willReturnSelf();
|
||||
$requestMock->expects($this->atLeastOnce())->method('setClient')->with($this->equalTo($clientMock))->willReturnSelf();
|
||||
|
||||
$this->assertInstanceOf(
|
||||
Request::class,
|
||||
$this->callMethod(
|
||||
$requestMock,
|
||||
'__construct',
|
||||
[$messageMock, $clientMock]
|
||||
)
|
||||
$this->callMethod(
|
||||
$requestMock,
|
||||
'__construct',
|
||||
[$messageMock, $clientMock]
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -149,7 +149,7 @@ class RecipientTest extends ApiTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[][]
|
||||
* @return array[]
|
||||
*/
|
||||
public function constructInvalidDataProvider(): array
|
||||
{
|
||||
|
@ -158,7 +158,7 @@ class SenderTest extends ApiTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[][]
|
||||
* @return array[]
|
||||
*/
|
||||
public function constructInvalidDataProvider(): array
|
||||
{
|
||||
|
@ -22,7 +22,7 @@ use Phlib\SmsLength\SmsLength;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use ReflectionException;
|
||||
|
||||
class SmsBinaryMessageTest extends ApiTestCase
|
||||
class SmsBinaryMessageTest extends SmsMessageAbstractTest
|
||||
{
|
||||
/** @var SmsBinaryMessage */
|
||||
public $message;
|
||||
@ -39,21 +39,12 @@ class SmsBinaryMessageTest extends ApiTestCase
|
||||
$this->message = new SmsBinaryMessage($this->messageFixture);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
unset($this->message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsBinaryMessage::__construct
|
||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsMessageAbstract::__construct
|
||||
*/
|
||||
public function testConstructValid()
|
||||
{
|
||||
@ -91,6 +82,7 @@ class SmsBinaryMessageTest extends ApiTestCase
|
||||
* @throws ReflectionException
|
||||
* @dataProvider constructInvalidDataProvider
|
||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsBinaryMessage::__construct
|
||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsMessageAbstract::__construct
|
||||
*/
|
||||
public function testConstructInvalid($binaryMessage, $valid, $expectedException)
|
||||
{
|
||||
@ -124,37 +116,11 @@ class SmsBinaryMessageTest extends ApiTestCase
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[][]
|
||||
*/
|
||||
public function constructInvalidDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'empty message' => ['', true, InvalidArgumentException::class],
|
||||
'invalid sms message' => ['abc', false, \Phlib\SmsLength\Exception\InvalidArgumentException::class],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsBinaryMessage::getSmsLength
|
||||
*/
|
||||
public function testGetSmsLengthInstance()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
SmsLength::class,
|
||||
$this->callMethod(
|
||||
$this->message,
|
||||
'getSmsLength'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsBinaryMessage::chunkCount
|
||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsMessageAbstract::chunkCount
|
||||
*/
|
||||
public function testGetChunkCount()
|
||||
{
|
||||
@ -170,9 +136,9 @@ class SmsBinaryMessageTest extends ApiTestCase
|
||||
|
||||
/** @var SmsBinaryMessage|MockObject $message */
|
||||
$message = $this->getMockBuilder(SmsBinaryMessage::class)
|
||||
->onlyMethods(['getSmsLength'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
->onlyMethods(['getSmsLength'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$message->method('getSmsLength')->willReturn($smsLengthMock);
|
||||
|
||||
$this->assertSame(
|
||||
@ -188,6 +154,7 @@ class SmsBinaryMessageTest extends ApiTestCase
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsBinaryMessage::length
|
||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsMessageAbstract::length
|
||||
*/
|
||||
public function testGetSize()
|
||||
{
|
||||
|
66
Tests/ValueObject/SmsMessageAbstractTest.php
Normal file
66
Tests/ValueObject/SmsMessageAbstractTest.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?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\ValueObject;
|
||||
|
||||
use Assert\InvalidArgumentException;
|
||||
use D3\LinkmobilityClient\Tests\ApiTestCase;
|
||||
use D3\LinkmobilityClient\ValueObject\SmsBinaryMessage;
|
||||
use Phlib\SmsLength\SmsLength;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use ReflectionException;
|
||||
|
||||
abstract class SmsMessageAbstractTest extends ApiTestCase
|
||||
{
|
||||
public $message;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
unset($this->message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array[]
|
||||
*/
|
||||
public function constructInvalidDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'empty message' => ['', true, InvalidArgumentException::class],
|
||||
'invalid sms message' => ['abc', false, \Phlib\SmsLength\Exception\InvalidArgumentException::class],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsBinaryMessage::getSmsLength
|
||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsTextMessage::getSmsLength
|
||||
*/
|
||||
public function testGetSmsLengthInstance()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
SmsLength::class,
|
||||
$this->callMethod(
|
||||
$this->message,
|
||||
'getSmsLength'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
@ -21,7 +21,7 @@ use Phlib\SmsLength\SmsLength;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use ReflectionException;
|
||||
|
||||
class SmsTextMessageTest extends SmsBinaryMessageTest
|
||||
class SmsTextMessageTest extends SmsMessageAbstractTest
|
||||
{
|
||||
/** @var SmsTextMessage */
|
||||
public $message;
|
||||
@ -43,6 +43,7 @@ class SmsTextMessageTest extends SmsBinaryMessageTest
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsTextMessage::__construct
|
||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsMessageAbstract::__construct
|
||||
*/
|
||||
public function testConstructValid()
|
||||
{
|
||||
@ -80,6 +81,7 @@ class SmsTextMessageTest extends SmsBinaryMessageTest
|
||||
* @throws ReflectionException
|
||||
* @dataProvider constructInvalidDataProvider
|
||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsTextMessage::__construct
|
||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsMessageAbstract::__construct
|
||||
*/
|
||||
public function testConstructInvalid($binaryMessage, $valid, $expectedException)
|
||||
{
|
||||
@ -112,4 +114,104 @@ class SmsTextMessageTest extends SmsBinaryMessageTest
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsTextMessage::chunkCount
|
||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsMessageAbstract::chunkCount
|
||||
*/
|
||||
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 SmsTextMessage|MockObject $message */
|
||||
$message = $this->getMockBuilder(SmsTextMessage::class)
|
||||
->onlyMethods(['getSmsLength'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$message->method('getSmsLength')->willReturn($smsLengthMock);
|
||||
|
||||
$this->assertSame(
|
||||
$expected,
|
||||
$this->callMethod(
|
||||
$message,
|
||||
'chunkCount'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsTextMessage::length
|
||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsMessageAbstract::length
|
||||
*/
|
||||
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 SmsTextMessage|MockObject $message */
|
||||
$message = $this->getMockBuilder(SmsTextMessage::class)
|
||||
->onlyMethods(['getSmsLength'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$message->method('getSmsLength')->willReturn($smsLengthMock);
|
||||
|
||||
$this->assertSame(
|
||||
$expected,
|
||||
$this->callMethod(
|
||||
$message,
|
||||
'length'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsTextMessage::getMessageContent
|
||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsMessageAbstract::getMessageContent
|
||||
*/
|
||||
public function testGetMessageContent()
|
||||
{
|
||||
/** @var SmsLength|MockObject $smsLengthMock */
|
||||
$smsLengthMock = $this->getMockBuilder(SmsLength::class)
|
||||
->onlyMethods(['validate'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$smsLengthMock->method('validate')->willReturn(true);
|
||||
|
||||
/** @var SmsTextMessage|MockObject $message */
|
||||
$message = $this->getMockBuilder(SmsTextMessage::class)
|
||||
->onlyMethods(['getSmsLength'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$message->method('getSmsLength')->willReturn($smsLengthMock);
|
||||
$message->__construct($this->messageFixture);
|
||||
|
||||
$this->assertSame(
|
||||
'testMessage',
|
||||
$this->callMethod(
|
||||
$message,
|
||||
'getMessageContent'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -45,6 +45,6 @@
|
||||
"test": "./vendor/bin/phpunit",
|
||||
"check-style": "./vendor/bin/php-cs-fixer fix --verbose --dry-run",
|
||||
"fix-style": "./vendor/bin/php-cs-fixer fix --verbose",
|
||||
"check-code": "./vendor/bin/phpstan -c phpstan.neon --no-progress --ansi"
|
||||
"check-code": "./vendor/bin/phpstan analyse -c phpstan.neon --no-progress --ansi"
|
||||
}
|
||||
}
|
||||
|
@ -2,5 +2,5 @@ parameters:
|
||||
paths:
|
||||
- src
|
||||
- Tests
|
||||
level: 2
|
||||
level: 5
|
||||
phpVersion: 70300
|
||||
|
@ -107,7 +107,7 @@ abstract class Request implements RequestInterface
|
||||
private $test = false;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
* @var int
|
||||
*/
|
||||
private $maxSmsPerMessage = 0;
|
||||
|
||||
@ -119,8 +119,6 @@ abstract class Request implements RequestInterface
|
||||
$this->recipientsList = new RecipientsList($client);
|
||||
$this->setMessage($message);
|
||||
$this->setClient($client);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -207,11 +205,11 @@ abstract class Request implements RequestInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param StringValueObject $message
|
||||
* @param SmsMessageInterface $message
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setMessage(StringValueObject $message): Request
|
||||
public function setMessage(SmsMessageInterface $message): Request
|
||||
{
|
||||
$this->message = $message;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user