Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
7e43fa1537
|
|||
b22da1bd4a
|
|||
95b95d1d8b
|
|||
d0db444157
|
|||
096ef7ed05
|
|||
dc0b680776
|
|||
05ff18d537
|
|||
05132f82ee
|
|||
f5579d9d5e
|
|||
4e5147a0ac
|
@ -6,7 +6,7 @@ $finder = PhpCsFixer\Finder::create()
|
|||||||
|
|
||||||
$config = new PhpCsFixer\Config();
|
$config = new PhpCsFixer\Config();
|
||||||
return $config->setRules([
|
return $config->setRules([
|
||||||
'@PHP70Migration' => true,
|
'@PHP73Migration' => true,
|
||||||
'@PSR12' => true
|
'@PSR12' => true
|
||||||
])
|
])
|
||||||
->setFinder($finder)
|
->setFinder($finder)
|
||||||
|
38
CHANGELOG.md
38
CHANGELOG.md
@ -2,6 +2,44 @@
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## 2.0.0.0 (2022-07-19)
|
||||||
|
|
||||||
|
- adjust to PHP >= 7.3 and current dependency packages
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 1.3.0.0 (2022-07-18)
|
||||||
|
|
||||||
|
- tests use generated example phone numbers
|
||||||
|
- move recipient checks from list to recipient itself
|
||||||
|
- tests added
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 1.2.1.0 (2022-07-15)
|
||||||
|
|
||||||
|
- extend log messages
|
||||||
|
- sanitize special phone number format before request
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 1.2.0.0 (2022-07-14)
|
||||||
|
|
||||||
|
- make sender number optional
|
||||||
|
- assign sender address type only if sender is set
|
||||||
|
- collect exception messages in a class
|
||||||
|
- collect URI parts in a class
|
||||||
|
- extract logger handler from client
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 1.1.0.0 (2022-07-13)
|
||||||
|
|
||||||
|
- make installable in PHP 8
|
||||||
|
- remove unused dependency
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## 1.0.0.0 (2022-07-13)
|
## 1.0.0.0 (2022-07-13)
|
||||||
|
|
||||||
- initial implementation
|
- initial implementation
|
||||||
|
@ -21,8 +21,10 @@ use Psr\Log\AbstractLogger;
|
|||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use ReflectionException;
|
use ReflectionException;
|
||||||
|
|
||||||
class LoggerHandlerTest extends ApiTestCase
|
class ALoggerHandlerTest extends ApiTestCase
|
||||||
{
|
{
|
||||||
|
/** tests must run as first, because of singleton, which must not initialized before */
|
||||||
|
|
||||||
/** @var LoggerHandler */
|
/** @var LoggerHandler */
|
||||||
public $loggerHandler;
|
public $loggerHandler;
|
||||||
|
|
||||||
@ -46,9 +48,30 @@ class LoggerHandlerTest extends ApiTestCase
|
|||||||
unset($this->loggerHandler);
|
unset($this->loggerHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @return void
|
||||||
|
* @covers \D3\LinkmobilityClient\LoggerHandler::getInstance
|
||||||
|
*/
|
||||||
|
public function testGetInstance()
|
||||||
|
{
|
||||||
|
// not existing instance
|
||||||
|
$this->assertInstanceOf(
|
||||||
|
LoggerHandler::class,
|
||||||
|
LoggerHandler::getInstance()
|
||||||
|
);
|
||||||
|
|
||||||
|
// existing instance
|
||||||
|
$this->assertInstanceOf(
|
||||||
|
LoggerHandler::class,
|
||||||
|
LoggerHandler::getInstance()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\LoggerHandler::__construct
|
||||||
*/
|
*/
|
||||||
public function testConstruct()
|
public function testConstruct()
|
||||||
{
|
{
|
||||||
@ -62,6 +85,8 @@ class LoggerHandlerTest extends ApiTestCase
|
|||||||
* @test
|
* @test
|
||||||
* @return void
|
* @return void
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\LoggerHandler::setLogger
|
||||||
|
* @covers \D3\LinkmobilityClient\LoggerHandler::getLogger
|
||||||
*/
|
*/
|
||||||
public function testLogger()
|
public function testLogger()
|
||||||
{
|
{
|
@ -68,6 +68,7 @@ class ClientTest extends ApiTestCase
|
|||||||
* @param $apiClient
|
* @param $apiClient
|
||||||
* @return void
|
* @return void
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\Client::__construct
|
||||||
*/
|
*/
|
||||||
public function testConstruct($apiKey, $apiUrl, $apiClient)
|
public function testConstruct($apiKey, $apiUrl, $apiClient)
|
||||||
{
|
{
|
||||||
@ -95,7 +96,7 @@ class ClientTest extends ApiTestCase
|
|||||||
return [
|
return [
|
||||||
'api key only' => ['apiKey', null, null],
|
'api key only' => ['apiKey', null, null],
|
||||||
'all without client' => ['apiKey', new Url(), null],
|
'all without client' => ['apiKey', new Url(), null],
|
||||||
'all arguments' => ['apiKey', new Url(), new GuzzleClient()]
|
'all arguments' => ['apiKey', new Url(), new GuzzleClient()],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,6 +105,7 @@ class ClientTest extends ApiTestCase
|
|||||||
* @return void
|
* @return void
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
* @dataProvider requestPassedDataProvider
|
* @dataProvider requestPassedDataProvider
|
||||||
|
* @covers \D3\LinkmobilityClient\Client::request
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function testRequest($requestIsValid)
|
public function testRequest($requestIsValid)
|
||||||
@ -165,7 +167,7 @@ class ClientTest extends ApiTestCase
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'request is valid' => [true],
|
'request is valid' => [true],
|
||||||
'request is not valid' => [false]
|
'request is not valid' => [false],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,6 +177,7 @@ class ClientTest extends ApiTestCase
|
|||||||
* @return void
|
* @return void
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
* @dataProvider rawRequestDataProvider
|
* @dataProvider rawRequestDataProvider
|
||||||
|
* @covers \D3\LinkmobilityClient\Client::rawRequest
|
||||||
*/
|
*/
|
||||||
public function testRawRequest($okStatus)
|
public function testRawRequest($okStatus)
|
||||||
{
|
{
|
||||||
@ -200,7 +203,7 @@ class ClientTest extends ApiTestCase
|
|||||||
'withHeader',
|
'withHeader',
|
||||||
'withAddedHeader',
|
'withAddedHeader',
|
||||||
'withoutHeader',
|
'withoutHeader',
|
||||||
'withBody'
|
'withBody',
|
||||||
])
|
])
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock();
|
||||||
@ -229,7 +232,7 @@ class ClientTest extends ApiTestCase
|
|||||||
$clientMock = $this->getMockBuilder(Client::class)
|
$clientMock = $this->getMockBuilder(Client::class)
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->onlyMethods([
|
->onlyMethods([
|
||||||
'getLoggerHandler'
|
'getLoggerHandler',
|
||||||
])
|
])
|
||||||
->getMock();
|
->getMock();
|
||||||
$clientMock->expects($this->atLeastOnce())
|
$clientMock->expects($this->atLeastOnce())
|
||||||
@ -255,4 +258,21 @@ class ClientTest extends ApiTestCase
|
|||||||
'NOK status' => [false],
|
'NOK status' => [false],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @return void
|
||||||
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\Client::getLoggerHandler
|
||||||
|
*/
|
||||||
|
public function testGetLoggerHandler()
|
||||||
|
{
|
||||||
|
$this->assertInstanceOf(
|
||||||
|
LoggerHandler::class,
|
||||||
|
$this->callMethod(
|
||||||
|
$this->api,
|
||||||
|
'getLoggerHandler'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,17 +16,13 @@ declare(strict_types=1);
|
|||||||
namespace D3\LinkmobilityClient\Tests\RecipientsList;
|
namespace D3\LinkmobilityClient\Tests\RecipientsList;
|
||||||
|
|
||||||
use D3\LinkmobilityClient\Client;
|
use D3\LinkmobilityClient\Client;
|
||||||
use D3\LinkmobilityClient\LoggerHandler;
|
|
||||||
use D3\LinkmobilityClient\RecipientsList\RecipientsList;
|
use D3\LinkmobilityClient\RecipientsList\RecipientsList;
|
||||||
use D3\LinkmobilityClient\Tests\ApiTestCase;
|
use D3\LinkmobilityClient\Tests\ApiTestCase;
|
||||||
use D3\LinkmobilityClient\ValueObject\Recipient;
|
use D3\LinkmobilityClient\ValueObject\Recipient;
|
||||||
use libphonenumber\NumberParseException;
|
use libphonenumber\PhoneNumberFormat;
|
||||||
use libphonenumber\PhoneNumber;
|
|
||||||
use libphonenumber\PhoneNumberType;
|
use libphonenumber\PhoneNumberType;
|
||||||
use libphonenumber\PhoneNumberUtil;
|
use libphonenumber\PhoneNumberUtil;
|
||||||
use PHPUnit\Framework\MockObject\MockObject;
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
use Psr\Log\AbstractLogger;
|
|
||||||
use Psr\Log\LoggerInterface;
|
|
||||||
use ReflectionException;
|
use ReflectionException;
|
||||||
use stdClass;
|
use stdClass;
|
||||||
|
|
||||||
@ -35,7 +31,7 @@ class RecipientsListTest extends ApiTestCase
|
|||||||
/** @var RecipientsList */
|
/** @var RecipientsList */
|
||||||
public $recipientsList;
|
public $recipientsList;
|
||||||
|
|
||||||
private $phoneNumberFixture = '01527565839';
|
private $phoneNumberFixture;
|
||||||
private $phoneCountryFixture = 'DE';
|
private $phoneCountryFixture = 'DE';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -51,6 +47,10 @@ class RecipientsListTest extends ApiTestCase
|
|||||||
->getMock();
|
->getMock();
|
||||||
|
|
||||||
$this->recipientsList = new RecipientsList($clientMock);
|
$this->recipientsList = new RecipientsList($clientMock);
|
||||||
|
|
||||||
|
$phoneUtil = PhoneNumberUtil::getInstance();
|
||||||
|
$example = $phoneUtil->getExampleNumberForType($this->phoneCountryFixture, PhoneNumberType::MOBILE);
|
||||||
|
$this->phoneNumberFixture = $phoneUtil->format($example, PhoneNumberFormat::NATIONAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -66,6 +66,7 @@ class RecipientsListTest extends ApiTestCase
|
|||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @return void
|
* @return void
|
||||||
|
* @covers \D3\LinkmobilityClient\RecipientsList\RecipientsList::__construct
|
||||||
*/
|
*/
|
||||||
public function testConstruct()
|
public function testConstruct()
|
||||||
{
|
{
|
||||||
@ -85,33 +86,10 @@ class RecipientsListTest extends ApiTestCase
|
|||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
*/
|
* @covers \D3\LinkmobilityClient\RecipientsList\RecipientsList::add
|
||||||
public function testGetPhoneNumberUtil()
|
|
||||||
{
|
|
||||||
$this->assertInstanceOf(
|
|
||||||
PhoneNumberUtil::class,
|
|
||||||
$this->callMethod(
|
|
||||||
$this->recipientsList,
|
|
||||||
'getPhoneNumberUtil'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @test
|
|
||||||
* @throws ReflectionException
|
|
||||||
*/
|
*/
|
||||||
public function testAddValidNumber()
|
public function testAddValidNumber()
|
||||||
{
|
{
|
||||||
/** @var PhoneNumberUtil|MockObject $phoneNumberUtilMock */
|
|
||||||
$phoneNumberUtilMock = $this->getMockBuilder(PhoneNumberUtil::class)
|
|
||||||
->onlyMethods(['parse', 'isValidNumber', 'getNumberType'])
|
|
||||||
->disableOriginalConstructor()
|
|
||||||
->getMock();
|
|
||||||
$phoneNumberUtilMock->method('parse')->willReturn(new PhoneNumber());
|
|
||||||
$phoneNumberUtilMock->method('isValidNumber')->willReturn(true);
|
|
||||||
$phoneNumberUtilMock->method('getNumberType')->willReturn(PhoneNumberType::MOBILE);
|
|
||||||
|
|
||||||
/** @var Recipient|MockObject $recipientMock */
|
/** @var Recipient|MockObject $recipientMock */
|
||||||
$recipientMock = $this->getMockBuilder(Recipient::class)
|
$recipientMock = $this->getMockBuilder(Recipient::class)
|
||||||
->onlyMethods(['get', 'getCountryCode'])
|
->onlyMethods(['get', 'getCountryCode'])
|
||||||
@ -120,15 +98,6 @@ class RecipientsListTest extends ApiTestCase
|
|||||||
$recipientMock->method('get')->willReturn($this->phoneNumberFixture);
|
$recipientMock->method('get')->willReturn($this->phoneNumberFixture);
|
||||||
$recipientMock->method('getCountryCode')->willReturn($this->phoneCountryFixture);
|
$recipientMock->method('getCountryCode')->willReturn($this->phoneCountryFixture);
|
||||||
|
|
||||||
/** @var RecipientsList|MockObject $recListMock */
|
|
||||||
$recListMock = $this->getMockBuilder(RecipientsList::class)
|
|
||||||
->onlyMethods(['getPhoneNumberUtil'])
|
|
||||||
->setConstructorArgs([$this->recipientsList->getClient()])
|
|
||||||
->getMock();
|
|
||||||
$recListMock->method('getPhoneNumberUtil')->willReturn($phoneNumberUtilMock);
|
|
||||||
|
|
||||||
$this->recipientsList = $recListMock;
|
|
||||||
|
|
||||||
$this->assertCount(
|
$this->assertCount(
|
||||||
0,
|
0,
|
||||||
$this->callMethod($this->recipientsList, 'getRecipientsList')
|
$this->callMethod($this->recipientsList, 'getRecipientsList')
|
||||||
@ -152,95 +121,8 @@ class RecipientsListTest extends ApiTestCase
|
|||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
* @dataProvider addInvalidNumberDataProvider
|
* @covers \D3\LinkmobilityClient\RecipientsList\RecipientsList::clearRecipents
|
||||||
*/
|
* @covers \D3\LinkmobilityClient\RecipientsList\RecipientsList::getRecipientsList
|
||||||
public function testAddInvalidNumber($unparsable, $invalidNumber, $invalidNumberType)
|
|
||||||
{
|
|
||||||
/** @var PhoneNumberUtil|MockObject $phoneNumberUtilMock */
|
|
||||||
$phoneNumberUtilMock = $this->getMockBuilder(PhoneNumberUtil::class)
|
|
||||||
->onlyMethods(['parse', 'isValidNumber', 'getNumberType'])
|
|
||||||
->disableOriginalConstructor()
|
|
||||||
->getMock();
|
|
||||||
|
|
||||||
if ($unparsable) {
|
|
||||||
$phoneNumberUtilMock->method('parse')->willThrowException(new NumberParseException(0, 'message'));
|
|
||||||
} else {
|
|
||||||
$phoneNumberUtilMock->method('parse')->willReturn(new PhoneNumber());
|
|
||||||
}
|
|
||||||
$phoneNumberUtilMock->method('isValidNumber')->willReturn(!$invalidNumber);
|
|
||||||
$phoneNumberUtilMock->method('getNumberType')->willReturn($invalidNumberType ? PhoneNumberType::FIXED_LINE : PhoneNumberType::MOBILE);
|
|
||||||
|
|
||||||
/** @var Recipient|MockObject $recipientMock */
|
|
||||||
$recipientMock = $this->getMockBuilder(Recipient::class)
|
|
||||||
->onlyMethods(['get', 'getCountryCode'])
|
|
||||||
->setConstructorArgs([$this->phoneNumberFixture, $this->phoneCountryFixture])
|
|
||||||
->getMock();
|
|
||||||
$recipientMock->method('get')->willReturn($this->phoneNumberFixture);
|
|
||||||
$recipientMock->method('getCountryCode')->willReturn($this->phoneCountryFixture);
|
|
||||||
|
|
||||||
/** @var LoggerInterface|MockObject $loggerMock */
|
|
||||||
$loggerMock = $this->getMockBuilder(AbstractLogger::class)
|
|
||||||
->onlyMethods(['info', 'log'])
|
|
||||||
->getMock();
|
|
||||||
$loggerMock->expects($this->atLeastOnce())->method('info')->willReturn(true);
|
|
||||||
|
|
||||||
/** @var LoggerHandler|MockObject $loggerHandlerMock */
|
|
||||||
$loggerHandlerMock = $this->getMockBuilder(LoggerHandler::class)
|
|
||||||
->onlyMethods(['getLogger'])
|
|
||||||
->getMock();
|
|
||||||
$loggerHandlerMock->method('getLogger')->willReturn($loggerMock);
|
|
||||||
|
|
||||||
/** @var Client|MockObject $clientMock */
|
|
||||||
$clientMock = $this->getMockBuilder(Client::class)
|
|
||||||
->disableOriginalConstructor()
|
|
||||||
->onlyMethods(['getLoggerHandler'])
|
|
||||||
->getMock();
|
|
||||||
$clientMock->method('getLoggerHandler')->willReturn($loggerHandlerMock);
|
|
||||||
|
|
||||||
/** @var RecipientsList|MockObject $recListMock */
|
|
||||||
$recListMock = $this->getMockBuilder(RecipientsList::class)
|
|
||||||
->onlyMethods(['getPhoneNumberUtil'])
|
|
||||||
->setConstructorArgs([$clientMock])
|
|
||||||
->getMock();
|
|
||||||
$recListMock->method('getPhoneNumberUtil')->willReturn($phoneNumberUtilMock);
|
|
||||||
|
|
||||||
$this->recipientsList = $recListMock;
|
|
||||||
|
|
||||||
$this->assertCount(
|
|
||||||
0,
|
|
||||||
$this->callMethod($this->recipientsList, 'getRecipientsList')
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->assertSame(
|
|
||||||
$this->recipientsList,
|
|
||||||
$this->callMethod(
|
|
||||||
$this->recipientsList,
|
|
||||||
'add',
|
|
||||||
[$recipientMock]
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->assertCount(
|
|
||||||
0,
|
|
||||||
$this->callMethod($this->recipientsList, 'getRecipientsList')
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array[]
|
|
||||||
*/
|
|
||||||
public function addInvalidNumberDataProvider(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'unparsable' => [true, false, false],
|
|
||||||
'invalid number' => [false, true, false],
|
|
||||||
'invalid number type' => [false, false, true],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @test
|
|
||||||
* @throws ReflectionException
|
|
||||||
*/
|
*/
|
||||||
public function testClearRecipents()
|
public function testClearRecipents()
|
||||||
{
|
{
|
||||||
@ -268,6 +150,7 @@ class RecipientsListTest extends ApiTestCase
|
|||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\RecipientsList\RecipientsList::getRecipients
|
||||||
*/
|
*/
|
||||||
public function testGetRecipients()
|
public function testGetRecipients()
|
||||||
{
|
{
|
||||||
@ -284,7 +167,7 @@ class RecipientsListTest extends ApiTestCase
|
|||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
[
|
[
|
||||||
$this->phoneNumberFixture,
|
$this->phoneNumberFixture,
|
||||||
$this->phoneNumberFixture
|
$this->phoneNumberFixture,
|
||||||
],
|
],
|
||||||
$this->callMethod(
|
$this->callMethod(
|
||||||
$this->recipientsList,
|
$this->recipientsList,
|
||||||
@ -296,6 +179,7 @@ class RecipientsListTest extends ApiTestCase
|
|||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\RecipientsList\RecipientsList::getRecipientsList
|
||||||
*/
|
*/
|
||||||
public function testGetRecipientsList()
|
public function testGetRecipientsList()
|
||||||
{
|
{
|
||||||
@ -327,6 +211,10 @@ class RecipientsListTest extends ApiTestCase
|
|||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\RecipientsList\RecipientsList::current
|
||||||
|
* @covers \D3\LinkmobilityClient\RecipientsList\RecipientsList::next
|
||||||
|
* @covers \D3\LinkmobilityClient\RecipientsList\RecipientsList::key
|
||||||
|
* @covers \D3\LinkmobilityClient\RecipientsList\RecipientsList::rewind
|
||||||
*/
|
*/
|
||||||
public function testCurrentNextKeyRewind()
|
public function testCurrentNextKeyRewind()
|
||||||
{
|
{
|
||||||
@ -375,6 +263,7 @@ class RecipientsListTest extends ApiTestCase
|
|||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\RecipientsList\RecipientsList::valid
|
||||||
*/
|
*/
|
||||||
public function testValid()
|
public function testValid()
|
||||||
{
|
{
|
||||||
@ -391,7 +280,7 @@ class RecipientsListTest extends ApiTestCase
|
|||||||
$this->recipientsList,
|
$this->recipientsList,
|
||||||
'recipients',
|
'recipients',
|
||||||
[
|
[
|
||||||
'fixture' => new stdClass()
|
'fixture' => new stdClass(),
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -406,13 +295,15 @@ class RecipientsListTest extends ApiTestCase
|
|||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\RecipientsList\RecipientsList::setClient
|
||||||
|
* @covers \D3\LinkmobilityClient\RecipientsList\RecipientsList::getClient
|
||||||
*/
|
*/
|
||||||
public function testSetGetClient()
|
public function testSetGetClient()
|
||||||
{
|
{
|
||||||
/** @var Client|MockObject $clientMock */
|
/** @var Client|MockObject $clientMock */
|
||||||
$clientMock = $this->getMockBuilder(Client::class)
|
$clientMock = $this->getMockBuilder(Client::class)
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock();
|
||||||
|
|
||||||
$this->assertInstanceOf(
|
$this->assertInstanceOf(
|
||||||
RecipientsList::class,
|
RecipientsList::class,
|
||||||
@ -442,11 +333,11 @@ class RecipientsListTest extends ApiTestCase
|
|||||||
$recipientMock = $this->getMockBuilder(Recipient::class)
|
$recipientMock = $this->getMockBuilder(Recipient::class)
|
||||||
->onlyMethods([
|
->onlyMethods([
|
||||||
'get',
|
'get',
|
||||||
'getCountryCode'
|
'getCountryCode',
|
||||||
])
|
])
|
||||||
->setConstructorArgs([
|
->setConstructorArgs([
|
||||||
$this->phoneNumberFixture,
|
$this->phoneNumberFixture,
|
||||||
$this->phoneCountryFixture
|
$this->phoneCountryFixture,
|
||||||
])
|
])
|
||||||
->getMock();
|
->getMock();
|
||||||
$recipientMock->method('get')->willReturn($this->phoneNumberFixture);
|
$recipientMock->method('get')->willReturn($this->phoneNumberFixture);
|
||||||
@ -456,11 +347,11 @@ class RecipientsListTest extends ApiTestCase
|
|||||||
$recipientMock2 = $this->getMockBuilder(Recipient::class)
|
$recipientMock2 = $this->getMockBuilder(Recipient::class)
|
||||||
->onlyMethods([
|
->onlyMethods([
|
||||||
'get',
|
'get',
|
||||||
'getCountryCode'
|
'getCountryCode',
|
||||||
])
|
])
|
||||||
->setConstructorArgs([
|
->setConstructorArgs([
|
||||||
$this->phoneNumberFixture,
|
$this->phoneNumberFixture,
|
||||||
$this->phoneCountryFixture
|
$this->phoneCountryFixture,
|
||||||
])
|
])
|
||||||
->getMock();
|
->getMock();
|
||||||
$recipientMock2->method('get')->willReturn($this->phoneNumberFixture);
|
$recipientMock2->method('get')->willReturn($this->phoneNumberFixture);
|
||||||
@ -468,7 +359,7 @@ class RecipientsListTest extends ApiTestCase
|
|||||||
|
|
||||||
$list = [
|
$list = [
|
||||||
'fixture' => $recipientMock,
|
'fixture' => $recipientMock,
|
||||||
'fixture2' => $recipientMock2
|
'fixture2' => $recipientMock2,
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->setValue(
|
$this->setValue(
|
||||||
|
@ -17,6 +17,7 @@ namespace D3\LinkmobilityClient\Tests\Request;
|
|||||||
|
|
||||||
use Assert\InvalidArgumentException;
|
use Assert\InvalidArgumentException;
|
||||||
use D3\LinkmobilityClient\Client;
|
use D3\LinkmobilityClient\Client;
|
||||||
|
use D3\LinkmobilityClient\Exceptions\RecipientException;
|
||||||
use D3\LinkmobilityClient\RecipientsList\RecipientsListInterface;
|
use D3\LinkmobilityClient\RecipientsList\RecipientsListInterface;
|
||||||
use D3\LinkmobilityClient\Request\Request;
|
use D3\LinkmobilityClient\Request\Request;
|
||||||
use D3\LinkmobilityClient\Request\RequestInterface;
|
use D3\LinkmobilityClient\Request\RequestInterface;
|
||||||
@ -24,6 +25,10 @@ use D3\LinkmobilityClient\SMS\Response;
|
|||||||
use D3\LinkmobilityClient\Tests\ApiTestCase;
|
use D3\LinkmobilityClient\Tests\ApiTestCase;
|
||||||
use D3\LinkmobilityClient\ValueObject\Recipient;
|
use D3\LinkmobilityClient\ValueObject\Recipient;
|
||||||
use D3\LinkmobilityClient\ValueObject\Sender;
|
use D3\LinkmobilityClient\ValueObject\Sender;
|
||||||
|
use libphonenumber\NumberParseException;
|
||||||
|
use libphonenumber\PhoneNumberFormat;
|
||||||
|
use libphonenumber\PhoneNumberType;
|
||||||
|
use libphonenumber\PhoneNumberUtil;
|
||||||
use PHPUnit\Framework\MockObject\MockObject;
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
use Psr\Http\Message\StreamInterface;
|
use Psr\Http\Message\StreamInterface;
|
||||||
@ -62,6 +67,8 @@ abstract class AbstractRequest extends ApiTestCase
|
|||||||
* @test
|
* @test
|
||||||
* @return void
|
* @return void
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::__construct
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\TextRequest::__construct
|
||||||
*/
|
*/
|
||||||
public function testConstruct()
|
public function testConstruct()
|
||||||
{
|
{
|
||||||
@ -95,6 +102,8 @@ abstract class AbstractRequest extends ApiTestCase
|
|||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::getUri
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\TextRequest::getUri
|
||||||
*/
|
*/
|
||||||
public function testGetUri()
|
public function testGetUri()
|
||||||
{
|
{
|
||||||
@ -108,11 +117,21 @@ abstract class AbstractRequest extends ApiTestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::validate
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\TextRequest::validate
|
||||||
|
* @covers \D3\LinkmobilityClient\Request\Request::validate
|
||||||
|
* @return void
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
|
* @throws RecipientException
|
||||||
|
* @throws NumberParseException
|
||||||
*/
|
*/
|
||||||
public function validatePassedTest()
|
public function validatePassedTest()
|
||||||
{
|
{
|
||||||
$recipient = new Recipient('015792300219', 'DE');
|
$phoneUtil = PhoneNumberUtil::getInstance();
|
||||||
|
$example = $phoneUtil->getExampleNumberForType('DE', PhoneNumberType::MOBILE);
|
||||||
|
$phoneNumberFixture = $phoneUtil->format($example, PhoneNumberFormat::NATIONAL);
|
||||||
|
|
||||||
|
$recipient = new Recipient($phoneNumberFixture, 'DE');
|
||||||
|
|
||||||
/** @var Request|MockObject $requestMock */
|
/** @var Request|MockObject $requestMock */
|
||||||
$requestMock = $this->getMockBuilder($this->testClassName)
|
$requestMock = $this->getMockBuilder($this->testClassName)
|
||||||
@ -135,11 +154,20 @@ abstract class AbstractRequest extends ApiTestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::validate
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\TextRequest::validate
|
||||||
|
* @return void
|
||||||
|
* @throws NumberParseException
|
||||||
|
* @throws RecipientException
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
*/
|
*/
|
||||||
public function validateFailedTest()
|
public function validateFailedTest()
|
||||||
{
|
{
|
||||||
$recipient = new Recipient('015792300219', 'DE');
|
$phoneUtil = PhoneNumberUtil::getInstance();
|
||||||
|
$example = $phoneUtil->getExampleNumberForType('DE', PhoneNumberType::MOBILE);
|
||||||
|
$phoneNumberFixture = $phoneUtil->format($example, PhoneNumberFormat::NATIONAL);
|
||||||
|
|
||||||
|
$recipient = new Recipient($phoneNumberFixture, 'DE');
|
||||||
|
|
||||||
/** @var Request|MockObject $requestMock */
|
/** @var Request|MockObject $requestMock */
|
||||||
$requestMock = $this->getMockBuilder($this->testClassName)
|
$requestMock = $this->getMockBuilder($this->testClassName)
|
||||||
@ -165,6 +193,9 @@ abstract class AbstractRequest extends ApiTestCase
|
|||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::getRawBody
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\TextRequest::getRawBody
|
||||||
|
* @covers \D3\LinkmobilityClient\Request\Request::getRawBody
|
||||||
*/
|
*/
|
||||||
public function testGetRawBody()
|
public function testGetRawBody()
|
||||||
{
|
{
|
||||||
@ -189,6 +220,8 @@ abstract class AbstractRequest extends ApiTestCase
|
|||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
* @dataProvider getBodyDataProvider
|
* @dataProvider getBodyDataProvider
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::getBody
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\TextRequest::getBody
|
||||||
*/
|
*/
|
||||||
public function testGetBody($contentType, $expected)
|
public function testGetBody($contentType, $expected)
|
||||||
{
|
{
|
||||||
@ -228,23 +261,25 @@ abstract class AbstractRequest extends ApiTestCase
|
|||||||
['json' => [
|
['json' => [
|
||||||
'contentCategory' => 'informational',
|
'contentCategory' => 'informational',
|
||||||
'messageContent' => 'messageContent',
|
'messageContent' => 'messageContent',
|
||||||
'priority' => 0
|
'priority' => 0,
|
||||||
]]
|
]],
|
||||||
],
|
],
|
||||||
'other' => [
|
'other' => [
|
||||||
'other',
|
'other',
|
||||||
[
|
[
|
||||||
'contentCategory' => 'informational',
|
'contentCategory' => 'informational',
|
||||||
'messageContent' => 'messageContent',
|
'messageContent' => 'messageContent',
|
||||||
'priority' => 0
|
'priority' => 0,
|
||||||
]
|
],
|
||||||
]
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::getOptions
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\TextRequest::getOptions
|
||||||
*/
|
*/
|
||||||
public function testGetOptions()
|
public function testGetOptions()
|
||||||
{
|
{
|
||||||
@ -257,20 +292,20 @@ abstract class AbstractRequest extends ApiTestCase
|
|||||||
['json' => [
|
['json' => [
|
||||||
'contentCategory' => 'informational',
|
'contentCategory' => 'informational',
|
||||||
'messageContent' => 'messageContent',
|
'messageContent' => 'messageContent',
|
||||||
'priority' => 0
|
'priority' => 0,
|
||||||
]]
|
]]
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
['headers' => [
|
['headers' => [
|
||||||
'Accept' => 'application/json',
|
'Accept' => 'application/json',
|
||||||
'Content-Type' => 'application/json'
|
'Content-Type' => 'application/json',
|
||||||
],
|
],
|
||||||
'json' => [
|
'json' => [
|
||||||
'contentCategory' => 'informational',
|
'contentCategory' => 'informational',
|
||||||
'messageContent' => 'messageContent',
|
'messageContent' => 'messageContent',
|
||||||
'priority' => 0
|
'priority' => 0,
|
||||||
]],
|
], ],
|
||||||
$this->callMethod(
|
$this->callMethod(
|
||||||
$requestMock,
|
$requestMock,
|
||||||
'getOptions'
|
'getOptions'
|
||||||
@ -304,6 +339,10 @@ abstract class AbstractRequest extends ApiTestCase
|
|||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::setMessage
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\TextRequest::setMessage
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::getMessage
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\TextRequest::getMessage
|
||||||
*/
|
*/
|
||||||
public function setGetMessageTest()
|
public function setGetMessageTest()
|
||||||
{
|
{
|
||||||
@ -317,6 +356,10 @@ abstract class AbstractRequest extends ApiTestCase
|
|||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::setMethod
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\TextRequest::setMethod
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::getMethod
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\TextRequest::getMethod
|
||||||
*/
|
*/
|
||||||
public function setGetMethodTest()
|
public function setGetMethodTest()
|
||||||
{
|
{
|
||||||
@ -326,6 +369,8 @@ abstract class AbstractRequest extends ApiTestCase
|
|||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::getMethods
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\TextRequest::getMethods
|
||||||
*/
|
*/
|
||||||
public function getMethodsTest()
|
public function getMethodsTest()
|
||||||
{
|
{
|
||||||
@ -341,6 +386,10 @@ abstract class AbstractRequest extends ApiTestCase
|
|||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::setContentType
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\TextRequest::setContentType
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::getContentType
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\TextRequest::getContentType
|
||||||
*/
|
*/
|
||||||
public function setGetContentTypeTest()
|
public function setGetContentTypeTest()
|
||||||
{
|
{
|
||||||
@ -350,6 +399,10 @@ abstract class AbstractRequest extends ApiTestCase
|
|||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::setClientMessageId
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\TextRequest::setClientMessageId
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::getClientMessageId
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\TextRequest::getClientMessageId
|
||||||
*/
|
*/
|
||||||
public function setGetClientMessageIdTest()
|
public function setGetClientMessageIdTest()
|
||||||
{
|
{
|
||||||
@ -359,6 +412,10 @@ abstract class AbstractRequest extends ApiTestCase
|
|||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::setContentCategory
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\TextRequest::setContentCategory
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::getContentCategory
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\TextRequest::getContentCategory
|
||||||
*/
|
*/
|
||||||
public function setGetContentCategoryTest()
|
public function setGetContentCategoryTest()
|
||||||
{
|
{
|
||||||
@ -368,6 +425,8 @@ abstract class AbstractRequest extends ApiTestCase
|
|||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::getContentCategories
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\TextRequest::getContentCategories
|
||||||
*/
|
*/
|
||||||
public function getContentCategoriesTest()
|
public function getContentCategoriesTest()
|
||||||
{
|
{
|
||||||
@ -383,6 +442,10 @@ abstract class AbstractRequest extends ApiTestCase
|
|||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::setTestMode
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\TextRequest::setTestMode
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::getTestMode
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\TextRequest::getTestMode
|
||||||
*/
|
*/
|
||||||
public function setGetTestModeTest()
|
public function setGetTestModeTest()
|
||||||
{
|
{
|
||||||
@ -392,6 +455,10 @@ abstract class AbstractRequest extends ApiTestCase
|
|||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::setMaxSmsPerMessage
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\TextRequest::setMaxSmsPerMessage
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::getMaxSmsPerMessage
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\TextRequest::getMaxSmsPerMessage
|
||||||
*/
|
*/
|
||||||
public function setGetMaxSmsPerMessageTest()
|
public function setGetMaxSmsPerMessageTest()
|
||||||
{
|
{
|
||||||
@ -401,6 +468,10 @@ abstract class AbstractRequest extends ApiTestCase
|
|||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::setMessageType
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\TextRequest::setMessageType
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::getMessageType
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\TextRequest::getMessageType
|
||||||
*/
|
*/
|
||||||
public function setGetMessageTypeTest()
|
public function setGetMessageTypeTest()
|
||||||
{
|
{
|
||||||
@ -410,6 +481,10 @@ abstract class AbstractRequest extends ApiTestCase
|
|||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::setNotificationCallbackUrl
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\TextRequest::setNotificationCallbackUrl
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::getNotificationCallbackUrl
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\TextRequest::getNotificationCallbackUrl
|
||||||
*/
|
*/
|
||||||
public function setGetNotificationCallbackUrlTest()
|
public function setGetNotificationCallbackUrlTest()
|
||||||
{
|
{
|
||||||
@ -419,6 +494,10 @@ abstract class AbstractRequest extends ApiTestCase
|
|||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::setPriority
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\TextRequest::setPriority
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::getPriority
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\TextRequest::getPriority
|
||||||
*/
|
*/
|
||||||
public function setGetPriorityTest()
|
public function setGetPriorityTest()
|
||||||
{
|
{
|
||||||
@ -428,6 +507,8 @@ abstract class AbstractRequest extends ApiTestCase
|
|||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::getRecipientsList
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\TextRequest::getRecipientsList
|
||||||
*/
|
*/
|
||||||
public function getRecipientsListTest()
|
public function getRecipientsListTest()
|
||||||
{
|
{
|
||||||
@ -443,6 +524,10 @@ abstract class AbstractRequest extends ApiTestCase
|
|||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::sendAsFlashSms
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\TextRequest::sendAsFlashSms
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::doSendAsFlashSms
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\TextRequest::doSendAsFlashSms
|
||||||
*/
|
*/
|
||||||
public function setGetFlashSmsTest()
|
public function setGetFlashSmsTest()
|
||||||
{
|
{
|
||||||
@ -452,6 +537,10 @@ abstract class AbstractRequest extends ApiTestCase
|
|||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::setSenderAddress
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\TextRequest::setSenderAddress
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::getSenderAddress
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\TextRequest::getSenderAddress
|
||||||
*/
|
*/
|
||||||
public function setGetSenderAddressTest()
|
public function setGetSenderAddressTest()
|
||||||
{
|
{
|
||||||
@ -466,6 +555,10 @@ abstract class AbstractRequest extends ApiTestCase
|
|||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
* @dataProvider setGetSenderAddressTypeDataProvider
|
* @dataProvider setGetSenderAddressTypeDataProvider
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::setSenderAddressType
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\TextRequest::setSenderAddressType
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::getSenderAddressType
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\TextRequest::getSenderAddressType
|
||||||
*/
|
*/
|
||||||
public function testSetGetSenderAddressType($hasSender, $addressType, $expected)
|
public function testSetGetSenderAddressType($hasSender, $addressType, $expected)
|
||||||
{
|
{
|
||||||
@ -519,6 +612,8 @@ abstract class AbstractRequest extends ApiTestCase
|
|||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::getSenderAddressTypes
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\TextRequest::getSenderAddressTypes
|
||||||
*/
|
*/
|
||||||
public function getSenderAddressTypesTest()
|
public function getSenderAddressTypesTest()
|
||||||
{
|
{
|
||||||
@ -534,6 +629,10 @@ abstract class AbstractRequest extends ApiTestCase
|
|||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::setValidityPeriode
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\TextRequest::setValidityPeriode
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::getValidityPeriode
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\TextRequest::getValidityPeriode
|
||||||
*/
|
*/
|
||||||
public function setGetValidityPeriodeTest()
|
public function setGetValidityPeriodeTest()
|
||||||
{
|
{
|
||||||
@ -544,6 +643,8 @@ abstract class AbstractRequest extends ApiTestCase
|
|||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
* @dataProvider getResponseInstanceDataProvider
|
* @dataProvider getResponseInstanceDataProvider
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::getResponseInstance
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\TextRequest::getResponseInstance
|
||||||
*/
|
*/
|
||||||
public function testGetResponseInstance(ResponseInterface $response)
|
public function testGetResponseInstance(ResponseInterface $response)
|
||||||
{
|
{
|
||||||
@ -578,7 +679,7 @@ abstract class AbstractRequest extends ApiTestCase
|
|||||||
/** @var StreamInterface|MockObject $streamMock */
|
/** @var StreamInterface|MockObject $streamMock */
|
||||||
$streamMock = $this->getMockBuilder(StreamInterface::class)
|
$streamMock = $this->getMockBuilder(StreamInterface::class)
|
||||||
->onlyMethods(['getContents', '__toString', 'close', 'detach', 'getSize', 'tell', 'eof', 'isSeekable',
|
->onlyMethods(['getContents', '__toString', 'close', 'detach', 'getSize', 'tell', 'eof', 'isSeekable',
|
||||||
'seek', 'rewind', 'isWritable', 'write', 'isReadable', 'read', 'getMetadata'])
|
'seek', 'rewind', 'isWritable', 'write', 'isReadable', 'read', 'getMetadata', ])
|
||||||
->getMock();
|
->getMock();
|
||||||
$streamMock->method('getContents')->willReturn('{}');
|
$streamMock->method('getContents')->willReturn('{}');
|
||||||
|
|
||||||
@ -587,18 +688,22 @@ abstract class AbstractRequest extends ApiTestCase
|
|||||||
->onlyMethods([
|
->onlyMethods([
|
||||||
'getBody', 'getStatusCode', 'withStatus', 'getReasonphrase', 'getProtocolVersion',
|
'getBody', 'getStatusCode', 'withStatus', 'getReasonphrase', 'getProtocolVersion',
|
||||||
'withProtocolVersion', 'getHeaders', 'hasHeader', 'getHeader', 'getHeaderLine',
|
'withProtocolVersion', 'getHeaders', 'hasHeader', 'getHeader', 'getHeaderLine',
|
||||||
'withHeader', 'withAddedHeader', 'withoutHeader', 'withBody'])
|
'withHeader', 'withAddedHeader', 'withoutHeader', 'withBody', ])
|
||||||
->getMock();
|
->getMock();
|
||||||
$rawResponseMock->method('getBody')->willReturn($streamMock);
|
$rawResponseMock->method('getBody')->willReturn($streamMock);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'SMS Response' => [$rawResponseMock]
|
'SMS Response' => [$rawResponseMock],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::setClient
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\TextRequest::setClient
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::getClient
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\TextRequest::getClient
|
||||||
*/
|
*/
|
||||||
public function setGetClientTest()
|
public function setGetClientTest()
|
||||||
{
|
{
|
||||||
@ -609,4 +714,33 @@ abstract class AbstractRequest extends ApiTestCase
|
|||||||
|
|
||||||
$this->checkGetterSetter($clientMock, 'setClient', 'getClient');
|
$this->checkGetterSetter($clientMock, 'setClient', 'getClient');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @return void
|
||||||
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::getResponseClass
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\TextRequest::getResponseClass
|
||||||
|
*/
|
||||||
|
public function testGetResponseClass()
|
||||||
|
{
|
||||||
|
$className = $this->callMethod(
|
||||||
|
$this->request,
|
||||||
|
'getResponseClass'
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertIsString(
|
||||||
|
$className
|
||||||
|
);
|
||||||
|
|
||||||
|
/** @var \D3\LinkmobilityClient\Response\ResponseInterface|MockObject $responseMock */
|
||||||
|
$responseMock = $this->getMockBuilder($className)
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->getMock();
|
||||||
|
|
||||||
|
$this->assertInstanceOf(
|
||||||
|
\D3\LinkmobilityClient\Response\ResponseInterface::class,
|
||||||
|
$responseMock
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,13 +29,16 @@ abstract class AbstractResponse extends ApiTestCase
|
|||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\Response::__construct
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\Response::getRawResponse
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\Response::getContent
|
||||||
*/
|
*/
|
||||||
public function testConstruct()
|
public function testConstruct()
|
||||||
{
|
{
|
||||||
/** @var StreamInterface|MockObject $streamMock */
|
/** @var StreamInterface|MockObject $streamMock */
|
||||||
$streamMock = $this->getMockBuilder(StreamInterface::class)
|
$streamMock = $this->getMockBuilder(StreamInterface::class)
|
||||||
->onlyMethods(['getContents', '__toString', 'close', 'detach', 'getSize', 'tell', 'eof', 'isSeekable',
|
->onlyMethods(['getContents', '__toString', 'close', 'detach', 'getSize', 'tell', 'eof', 'isSeekable',
|
||||||
'seek', 'rewind', 'isWritable', 'write', 'isReadable', 'read', 'getMetadata'])
|
'seek', 'rewind', 'isWritable', 'write', 'isReadable', 'read', 'getMetadata', ])
|
||||||
->getMock();
|
->getMock();
|
||||||
$streamMock->expects($this->atLeastOnce())->method('getContents')->willReturn(
|
$streamMock->expects($this->atLeastOnce())->method('getContents')->willReturn(
|
||||||
'{
|
'{
|
||||||
@ -50,7 +53,7 @@ abstract class AbstractResponse extends ApiTestCase
|
|||||||
->onlyMethods([
|
->onlyMethods([
|
||||||
'getBody', 'getStatusCode', 'withStatus', 'getReasonphrase', 'getProtocolVersion',
|
'getBody', 'getStatusCode', 'withStatus', 'getReasonphrase', 'getProtocolVersion',
|
||||||
'withProtocolVersion', 'getHeaders', 'hasHeader', 'getHeader', 'getHeaderLine',
|
'withProtocolVersion', 'getHeaders', 'hasHeader', 'getHeader', 'getHeaderLine',
|
||||||
'withHeader', 'withAddedHeader', 'withoutHeader', 'withBody'])
|
'withHeader', 'withAddedHeader', 'withoutHeader', 'withBody', ])
|
||||||
->getMock();
|
->getMock();
|
||||||
$rawResponseMock->method('getBody')->willReturn($streamMock);
|
$rawResponseMock->method('getBody')->willReturn($streamMock);
|
||||||
|
|
||||||
@ -102,6 +105,7 @@ abstract class AbstractResponse extends ApiTestCase
|
|||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\Response::getInternalStatus
|
||||||
*/
|
*/
|
||||||
public function testGetInternalStatus()
|
public function testGetInternalStatus()
|
||||||
{
|
{
|
||||||
@ -111,6 +115,7 @@ abstract class AbstractResponse extends ApiTestCase
|
|||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\Response::getStatusMessage
|
||||||
*/
|
*/
|
||||||
public function testGetStatusMessage()
|
public function testGetStatusMessage()
|
||||||
{
|
{
|
||||||
@ -120,6 +125,17 @@ abstract class AbstractResponse extends ApiTestCase
|
|||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\Response::getClientMessageId
|
||||||
|
*/
|
||||||
|
public function testGetClientMessageId()
|
||||||
|
{
|
||||||
|
$this->checkProperties('clientMessageId', 'clientMessageId', 'getClientMessageId');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\Response::getTransferId
|
||||||
*/
|
*/
|
||||||
public function testGetTransferId()
|
public function testGetTransferId()
|
||||||
{
|
{
|
||||||
@ -129,6 +145,7 @@ abstract class AbstractResponse extends ApiTestCase
|
|||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\Response::getSmsCount
|
||||||
*/
|
*/
|
||||||
public function testGetSmsCount()
|
public function testGetSmsCount()
|
||||||
{
|
{
|
||||||
@ -142,6 +159,7 @@ abstract class AbstractResponse extends ApiTestCase
|
|||||||
*
|
*
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
* @dataProvider isSuccessfulDataProvider
|
* @dataProvider isSuccessfulDataProvider
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\Response::isSuccessful
|
||||||
*/
|
*/
|
||||||
public function testIsSuccessful($statusCode, $expected)
|
public function testIsSuccessful($statusCode, $expected)
|
||||||
{
|
{
|
||||||
@ -180,6 +198,7 @@ abstract class AbstractResponse extends ApiTestCase
|
|||||||
*
|
*
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
* @dataProvider getErrorMessageDataProvider
|
* @dataProvider getErrorMessageDataProvider
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\Response::getErrorMessage
|
||||||
*/
|
*/
|
||||||
public function testGetErrorMessage($successful, $expected)
|
public function testGetErrorMessage($successful, $expected)
|
||||||
{
|
{
|
||||||
@ -207,7 +226,7 @@ abstract class AbstractResponse extends ApiTestCase
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'successful' => [true, ''],
|
'successful' => [true, ''],
|
||||||
'not successful'=> [false, 'fixtureMessage']
|
'not successful'=> [false, 'fixtureMessage'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,7 @@ class RequestFactoryTest extends ApiTestCase
|
|||||||
* @test
|
* @test
|
||||||
* @return void
|
* @return void
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\RequestFactory::__construct
|
||||||
*/
|
*/
|
||||||
public function testConstruct()
|
public function testConstruct()
|
||||||
{
|
{
|
||||||
@ -59,6 +60,7 @@ class RequestFactoryTest extends ApiTestCase
|
|||||||
* @return void
|
* @return void
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
* @dataProvider getTextSmsRequestDataProvider
|
* @dataProvider getTextSmsRequestDataProvider
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\RequestFactory::getSmsRequest
|
||||||
*/
|
*/
|
||||||
public function testGetTextSmsRequest($encoding, $expectedClass)
|
public function testGetTextSmsRequest($encoding, $expectedClass)
|
||||||
{
|
{
|
||||||
@ -98,8 +100,8 @@ class RequestFactoryTest extends ApiTestCase
|
|||||||
public function getTextSmsRequestDataProvider(): array
|
public function getTextSmsRequestDataProvider(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'binary' => [RequestFactory::GSM_UCS2, BinaryRequest::class],
|
'binary' => [SmsLength::ENCODING_UCS2, BinaryRequest::class],
|
||||||
'ascii' => [RequestFactory::GSM_7BIT, TextRequest::class]
|
'ascii' => [SmsLength::ENCODING_7BIT, TextRequest::class],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,6 +109,7 @@ class RequestFactoryTest extends ApiTestCase
|
|||||||
* @test
|
* @test
|
||||||
* @return void
|
* @return void
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\SMS\RequestFactory::getSmsLength
|
||||||
*/
|
*/
|
||||||
public function testGetSmsLengthInstance()
|
public function testGetSmsLengthInstance()
|
||||||
{
|
{
|
||||||
|
@ -45,6 +45,7 @@ class UrlTest extends ApiTestCase
|
|||||||
* @test
|
* @test
|
||||||
* @return void
|
* @return void
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\Url\Url::getBaseUri
|
||||||
*/
|
*/
|
||||||
public function testGetBaseUri()
|
public function testGetBaseUri()
|
||||||
{
|
{
|
||||||
@ -63,6 +64,7 @@ class UrlTest extends ApiTestCase
|
|||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\Url\Url::getTextSmsUri
|
||||||
*/
|
*/
|
||||||
public function testGetTextSmsUri()
|
public function testGetTextSmsUri()
|
||||||
{
|
{
|
||||||
@ -78,6 +80,7 @@ class UrlTest extends ApiTestCase
|
|||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\Url\Url::getBinarySmsUri
|
||||||
*/
|
*/
|
||||||
public function testGetBinarySmsUri()
|
public function testGetBinarySmsUri()
|
||||||
{
|
{
|
||||||
|
@ -16,10 +16,13 @@ declare(strict_types=1);
|
|||||||
namespace D3\LinkmobilityClient\Tests\ValueObject;
|
namespace D3\LinkmobilityClient\Tests\ValueObject;
|
||||||
|
|
||||||
use Assert\InvalidArgumentException;
|
use Assert\InvalidArgumentException;
|
||||||
|
use D3\LinkmobilityClient\Exceptions\RecipientException;
|
||||||
use D3\LinkmobilityClient\Tests\ApiTestCase;
|
use D3\LinkmobilityClient\Tests\ApiTestCase;
|
||||||
use D3\LinkmobilityClient\ValueObject\Recipient;
|
use D3\LinkmobilityClient\ValueObject\Recipient;
|
||||||
use libphonenumber\NumberParseException;
|
use libphonenumber\NumberParseException;
|
||||||
use libphonenumber\PhoneNumber;
|
use libphonenumber\PhoneNumber;
|
||||||
|
use libphonenumber\PhoneNumberFormat;
|
||||||
|
use libphonenumber\PhoneNumberType;
|
||||||
use libphonenumber\PhoneNumberUtil;
|
use libphonenumber\PhoneNumberUtil;
|
||||||
use PHPUnit\Framework\MockObject\MockObject;
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
use ReflectionException;
|
use ReflectionException;
|
||||||
@ -29,17 +32,22 @@ class RecipientTest extends ApiTestCase
|
|||||||
/** @var Recipient */
|
/** @var Recipient */
|
||||||
public $recipient;
|
public $recipient;
|
||||||
|
|
||||||
private $phoneNumberFixture = '01527565839';
|
private $phoneNumberFixture;
|
||||||
private $phoneCountryFixture = 'DE';
|
private $phoneCountryFixture = 'DE';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return void
|
* @return void
|
||||||
* @throws NumberParseException
|
* @throws NumberParseException
|
||||||
|
* @throws RecipientException
|
||||||
*/
|
*/
|
||||||
public function setUp(): void
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
|
$phoneUtil = PhoneNumberUtil::getInstance();
|
||||||
|
$example = $phoneUtil->getExampleNumberForType($this->phoneCountryFixture, PhoneNumberType::MOBILE);
|
||||||
|
$this->phoneNumberFixture = $phoneUtil->format($example, PhoneNumberFormat::NATIONAL);
|
||||||
|
|
||||||
$this->recipient = new Recipient($this->phoneNumberFixture, $this->phoneCountryFixture);
|
$this->recipient = new Recipient($this->phoneNumberFixture, $this->phoneCountryFixture);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,17 +65,21 @@ class RecipientTest extends ApiTestCase
|
|||||||
* @test
|
* @test
|
||||||
* @return void
|
* @return void
|
||||||
* @throws NumberParseException
|
* @throws NumberParseException
|
||||||
|
* @throws RecipientException
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\ValueObject\Recipient::__construct
|
||||||
*/
|
*/
|
||||||
public function testConstructValid()
|
public function testConstructValid()
|
||||||
{
|
{
|
||||||
/** @var PhoneNumberUtil|MockObject $phoneNumberUtilMock */
|
/** @var PhoneNumberUtil|MockObject $phoneNumberUtilMock */
|
||||||
$phoneNumberUtilMock = $this->getMockBuilder(PhoneNumberUtil::class)
|
$phoneNumberUtilMock = $this->getMockBuilder(PhoneNumberUtil::class)
|
||||||
->onlyMethods(['parse', 'format'])
|
->onlyMethods(['parse', 'format', 'isValidNumber', 'getNumberType'])
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock();
|
||||||
$phoneNumberUtilMock->method('parse')->willReturn(new PhoneNumber());
|
$phoneNumberUtilMock->method('parse')->willReturn(new PhoneNumber());
|
||||||
$phoneNumberUtilMock->method('format')->willReturn('+491527565839');
|
$phoneNumberUtilMock->method('format')->willReturn('+491527565839');
|
||||||
|
$phoneNumberUtilMock->method('isValidNumber')->willReturn(true);
|
||||||
|
$phoneNumberUtilMock->method('getNumberType')->willReturn(PhoneNumberType::MOBILE);
|
||||||
|
|
||||||
/** @var Recipient|MockObject $recipientMock */
|
/** @var Recipient|MockObject $recipientMock */
|
||||||
$recipientMock = $this->getMockBuilder(Recipient::class)
|
$recipientMock = $this->getMockBuilder(Recipient::class)
|
||||||
@ -100,17 +112,20 @@ class RecipientTest extends ApiTestCase
|
|||||||
* @param $number
|
* @param $number
|
||||||
* @param $country
|
* @param $country
|
||||||
* @param $validNumber
|
* @param $validNumber
|
||||||
|
* @param $numberType
|
||||||
* @param $expectedException
|
* @param $expectedException
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
* @throws NumberParseException
|
* @throws NumberParseException
|
||||||
|
* @throws RecipientException
|
||||||
* @dataProvider constructInvalidDataProvider
|
* @dataProvider constructInvalidDataProvider
|
||||||
|
* @covers \D3\LinkmobilityClient\ValueObject\Recipient::__construct
|
||||||
*/
|
*/
|
||||||
public function testConstructInvalid($number, $country, $validNumber, $expectedException)
|
public function testConstructInvalid($number, $country, $validNumber, $numberType, $expectedException)
|
||||||
{
|
{
|
||||||
/** @var PhoneNumberUtil|MockObject $phoneNumberUtilMock */
|
/** @var PhoneNumberUtil|MockObject $phoneNumberUtilMock */
|
||||||
$phoneNumberUtilMock = $this->getMockBuilder(PhoneNumberUtil::class)
|
$phoneNumberUtilMock = $this->getMockBuilder(PhoneNumberUtil::class)
|
||||||
->onlyMethods(['parse', 'format', 'isValidNumber'])
|
->onlyMethods(['parse', 'format', 'isValidNumber', 'getNumberType'])
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock();
|
||||||
if ($number === 'abc') {
|
if ($number === 'abc') {
|
||||||
@ -120,6 +135,7 @@ class RecipientTest extends ApiTestCase
|
|||||||
}
|
}
|
||||||
$phoneNumberUtilMock->method('format')->willReturn($number);
|
$phoneNumberUtilMock->method('format')->willReturn($number);
|
||||||
$phoneNumberUtilMock->method('isValidNumber')->willReturn($validNumber);
|
$phoneNumberUtilMock->method('isValidNumber')->willReturn($validNumber);
|
||||||
|
$phoneNumberUtilMock->method('getNumberType')->willReturn($numberType);
|
||||||
|
|
||||||
/** @var Recipient|MockObject $recipientMock */
|
/** @var Recipient|MockObject $recipientMock */
|
||||||
$recipientMock = $this->getMockBuilder(Recipient::class)
|
$recipientMock = $this->getMockBuilder(Recipient::class)
|
||||||
@ -137,17 +153,23 @@ class RecipientTest extends ApiTestCase
|
|||||||
*/
|
*/
|
||||||
public function constructInvalidDataProvider(): array
|
public function constructInvalidDataProvider(): array
|
||||||
{
|
{
|
||||||
|
$phoneUtil = PhoneNumberUtil::getInstance();
|
||||||
|
$example = $phoneUtil->getExampleNumberForType($this->phoneCountryFixture, PhoneNumberType::MOBILE);
|
||||||
|
$phoneNumberFixture = $phoneUtil->format($example, PhoneNumberFormat::NATIONAL);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'empty number' => ['', 'DE', true, InvalidArgumentException::class],
|
'empty number' => ['', 'DE', true, PhoneNumberType::MOBILE, InvalidArgumentException::class],
|
||||||
'invalid country code' => [$this->phoneNumberFixture, 'DEX', true, InvalidArgumentException::class],
|
'invalid country code' => [$phoneNumberFixture, 'DEX', true, PhoneNumberType::MOBILE, InvalidArgumentException::class],
|
||||||
'unparsable' => ['abc', 'DE', true, NumberParseException::class],
|
'unparsable' => ['abc', 'DE', true, PhoneNumberType::MOBILE, NumberParseException::class],
|
||||||
'invalid number' => ['abc', 'DE', false, NumberParseException::class]
|
'invalid number' => ['abcd', 'DE', false, PhoneNumberType::MOBILE, RecipientException::class],
|
||||||
|
'not mobile number' => ['abcd', 'DE', true, PhoneNumberType::FIXED_LINE, RecipientException::class],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\ValueObject\Recipient::getPhoneNumberUtil
|
||||||
*/
|
*/
|
||||||
public function testGetPhoneNumberUtil()
|
public function testGetPhoneNumberUtil()
|
||||||
{
|
{
|
||||||
@ -159,4 +181,65 @@ class RecipientTest extends ApiTestCase
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @return void
|
||||||
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\ValueObject\Recipient::getCountryCode
|
||||||
|
*/
|
||||||
|
public function testGetCountryCode()
|
||||||
|
{
|
||||||
|
$this->assertSame(
|
||||||
|
$this->phoneCountryFixture,
|
||||||
|
$this->callMethod(
|
||||||
|
$this->recipient,
|
||||||
|
'getCountryCode'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @return void
|
||||||
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\ValueObject\ValueObject::get
|
||||||
|
* @covers \D3\LinkmobilityClient\ValueObject\StringValueObject::get
|
||||||
|
* @covers \D3\LinkmobilityClient\ValueObject\StringValueObject::__toString
|
||||||
|
* @covers \D3\LinkmobilityClient\ValueObject\Recipient::get
|
||||||
|
*/
|
||||||
|
public function testGet()
|
||||||
|
{
|
||||||
|
$this->assertSame(
|
||||||
|
'+4915123456789',
|
||||||
|
(string) $this->recipient
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertSame(
|
||||||
|
'+4915123456789',
|
||||||
|
$this->callMethod(
|
||||||
|
$this->recipient,
|
||||||
|
'get'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @return void
|
||||||
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\ValueObject\ValueObject::getFormatted
|
||||||
|
* @covers \D3\LinkmobilityClient\ValueObject\StringValueObject::getFormatted
|
||||||
|
* @covers \D3\LinkmobilityClient\ValueObject\Recipient::getFormatted
|
||||||
|
*/
|
||||||
|
public function testGetFormatted()
|
||||||
|
{
|
||||||
|
$this->assertSame(
|
||||||
|
'4915123456789',
|
||||||
|
$this->callMethod(
|
||||||
|
$this->recipient,
|
||||||
|
'getFormatted'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,8 @@ use D3\LinkmobilityClient\Tests\ApiTestCase;
|
|||||||
use D3\LinkmobilityClient\ValueObject\Sender;
|
use D3\LinkmobilityClient\ValueObject\Sender;
|
||||||
use libphonenumber\NumberParseException;
|
use libphonenumber\NumberParseException;
|
||||||
use libphonenumber\PhoneNumber;
|
use libphonenumber\PhoneNumber;
|
||||||
|
use libphonenumber\PhoneNumberFormat;
|
||||||
|
use libphonenumber\PhoneNumberType;
|
||||||
use libphonenumber\PhoneNumberUtil;
|
use libphonenumber\PhoneNumberUtil;
|
||||||
use PHPUnit\Framework\MockObject\MockObject;
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
use ReflectionException;
|
use ReflectionException;
|
||||||
@ -30,7 +32,7 @@ class SenderTest extends ApiTestCase
|
|||||||
/** @var Sender */
|
/** @var Sender */
|
||||||
public $sender;
|
public $sender;
|
||||||
|
|
||||||
private $phoneNumberFixture = '015792300219';
|
private $phoneNumberFixture;
|
||||||
private $phoneCountryFixture = 'DE';
|
private $phoneCountryFixture = 'DE';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -42,6 +44,11 @@ class SenderTest extends ApiTestCase
|
|||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
|
$phoneUtil = PhoneNumberUtil::getInstance();
|
||||||
|
$example = $phoneUtil->getExampleNumberForType($this->phoneCountryFixture, PhoneNumberType::MOBILE);
|
||||||
|
$this->phoneNumberFixture = $phoneUtil->format($example, PhoneNumberFormat::NATIONAL);
|
||||||
|
|
||||||
|
/** @var Sender|MockObject sender */
|
||||||
$this->sender = new Sender($this->phoneNumberFixture, $this->phoneCountryFixture);
|
$this->sender = new Sender($this->phoneNumberFixture, $this->phoneCountryFixture);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,8 +68,10 @@ class SenderTest extends ApiTestCase
|
|||||||
* @throws NumberParseException
|
* @throws NumberParseException
|
||||||
* @throws RecipientException
|
* @throws RecipientException
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
|
* @dataProvider constructValidDataProvider
|
||||||
|
* @covers \D3\LinkmobilityClient\ValueObject\Sender::__construct
|
||||||
*/
|
*/
|
||||||
public function testConstructValid()
|
public function testConstructValid($number, $country, $hasNumber)
|
||||||
{
|
{
|
||||||
/** @var PhoneNumberUtil|MockObject $phoneNumberUtilMock */
|
/** @var PhoneNumberUtil|MockObject $phoneNumberUtilMock */
|
||||||
$phoneNumberUtilMock = $this->getMockBuilder(PhoneNumberUtil::class)
|
$phoneNumberUtilMock = $this->getMockBuilder(PhoneNumberUtil::class)
|
||||||
@ -79,27 +88,42 @@ class SenderTest extends ApiTestCase
|
|||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock();
|
||||||
$senderMock->method('getPhoneNumberUtil')->willReturn($phoneNumberUtilMock);
|
$senderMock->method('getPhoneNumberUtil')->willReturn($phoneNumberUtilMock);
|
||||||
$senderMock->__construct($this->phoneNumberFixture, $this->phoneCountryFixture);
|
$senderMock->__construct($number, $country);
|
||||||
|
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
'4915792300219',
|
$hasNumber,
|
||||||
$this->callMethod(
|
$this->callMethod(
|
||||||
$senderMock,
|
$senderMock,
|
||||||
'get'
|
'get'
|
||||||
)
|
) === '4915792300219'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array[]
|
||||||
|
*/
|
||||||
|
public function constructValidDataProvider(): array
|
||||||
|
{
|
||||||
|
$phoneUtil = PhoneNumberUtil::getInstance();
|
||||||
|
$example = $phoneUtil->getExampleNumberForType($this->phoneCountryFixture, PhoneNumberType::MOBILE);
|
||||||
|
$this->phoneNumberFixture = $phoneUtil->format($example, PhoneNumberFormat::NATIONAL);
|
||||||
|
|
||||||
|
return [
|
||||||
|
'null number' => [null, $this->phoneCountryFixture, false],
|
||||||
|
'null country' => [$this->phoneNumberFixture, null, false],
|
||||||
|
'all values' => [$this->phoneNumberFixture, $this->phoneCountryFixture, true],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @param $number
|
* @param $number
|
||||||
* @param $country
|
* @param $country
|
||||||
* @param $validNumber
|
* @param $validNumber
|
||||||
* @param $expectedException
|
* @param $expectedException
|
||||||
*
|
* @throws ReflectionException
|
||||||
* @throws NumberParseException
|
|
||||||
* @throws RecipientException
|
|
||||||
* @dataProvider constructInvalidDataProvider
|
* @dataProvider constructInvalidDataProvider
|
||||||
|
* @covers \D3\LinkmobilityClient\ValueObject\Sender::__construct
|
||||||
*/
|
*/
|
||||||
public function testConstructInvalid($number, $country, $validNumber, $expectedException)
|
public function testConstructInvalid($number, $country, $validNumber, $expectedException)
|
||||||
{
|
{
|
||||||
@ -109,12 +133,14 @@ class SenderTest extends ApiTestCase
|
|||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock();
|
||||||
if ($number === 'abc') {
|
if ($number === 'abc') {
|
||||||
$phoneNumberUtilMock->method('parse')->willThrowException(new NumberParseException(0, 'message'));
|
$phoneNumberUtilMock->expects($this->exactly((int) ($country !== 'DEX')))->method('parse')
|
||||||
|
->willThrowException(new NumberParseException(0, 'message'));
|
||||||
} else {
|
} else {
|
||||||
$phoneNumberUtilMock->method('parse')->willReturn(new PhoneNumber());
|
$phoneNumberUtilMock->expects($this->exactly((int) ($country !== 'DEX')))->method('parse')
|
||||||
|
->willReturn(new PhoneNumber());
|
||||||
}
|
}
|
||||||
$phoneNumberUtilMock->method('format')->willReturn($number);
|
$phoneNumberUtilMock->method('format')->willReturn($number);
|
||||||
$phoneNumberUtilMock->method('isValidNumber')->willReturn($validNumber);
|
$phoneNumberUtilMock->method('isValidNumber')->willReturn((bool) $validNumber);
|
||||||
|
|
||||||
/** @var Sender|MockObject $senderMock */
|
/** @var Sender|MockObject $senderMock */
|
||||||
$senderMock = $this->getMockBuilder(Sender::class)
|
$senderMock = $this->getMockBuilder(Sender::class)
|
||||||
@ -124,7 +150,12 @@ class SenderTest extends ApiTestCase
|
|||||||
$senderMock->method('getPhoneNumberUtil')->willReturn($phoneNumberUtilMock);
|
$senderMock->method('getPhoneNumberUtil')->willReturn($phoneNumberUtilMock);
|
||||||
|
|
||||||
$this->expectException($expectedException);
|
$this->expectException($expectedException);
|
||||||
$senderMock->__construct($number, $country);
|
|
||||||
|
$this->callMethod(
|
||||||
|
$senderMock,
|
||||||
|
'__construct',
|
||||||
|
[$number, $country]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -132,17 +163,22 @@ class SenderTest extends ApiTestCase
|
|||||||
*/
|
*/
|
||||||
public function constructInvalidDataProvider(): array
|
public function constructInvalidDataProvider(): array
|
||||||
{
|
{
|
||||||
|
$phoneUtil = PhoneNumberUtil::getInstance();
|
||||||
|
$example = $phoneUtil->getExampleNumberForType($this->phoneCountryFixture, PhoneNumberType::MOBILE);
|
||||||
|
$phoneNumberFixture = $phoneUtil->format($example, PhoneNumberFormat::NATIONAL);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'empty number' => ['', 'DE', true, InvalidArgumentException::class],
|
'empty number' => ['', 'DE', true, InvalidArgumentException::class],
|
||||||
'invalid country code' => [$this->phoneNumberFixture, 'DEX', true, InvalidArgumentException::class],
|
'invalid country code' => [$phoneNumberFixture, 'DEX', true, InvalidArgumentException::class],
|
||||||
'unparsable' => ['abc', 'DE', true, NumberParseException::class],
|
'unparsable' => ['abc', 'DE', true, NumberParseException::class],
|
||||||
'invalid number' => ['abc', 'DE', false, NumberParseException::class]
|
'invalid number' => ['abcd', 'DE', false, RecipientException::class],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\ValueObject\Sender::getPhoneNumberUtil
|
||||||
*/
|
*/
|
||||||
public function testGetPhoneNumberUtil()
|
public function testGetPhoneNumberUtil()
|
||||||
{
|
{
|
||||||
@ -154,4 +190,42 @@ class SenderTest extends ApiTestCase
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @return void
|
||||||
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\ValueObject\ValueObject::get
|
||||||
|
* @covers \D3\LinkmobilityClient\ValueObject\StringValueObject::get
|
||||||
|
* @covers \D3\LinkmobilityClient\ValueObject\Sender::get
|
||||||
|
*/
|
||||||
|
public function testGet()
|
||||||
|
{
|
||||||
|
$this->assertSame(
|
||||||
|
'+4915123456789',
|
||||||
|
$this->callMethod(
|
||||||
|
$this->sender,
|
||||||
|
'get'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @return void
|
||||||
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\ValueObject\ValueObject::getFormatted
|
||||||
|
* @covers \D3\LinkmobilityClient\ValueObject\StringValueObject::getFormatted
|
||||||
|
* @covers \D3\LinkmobilityClient\ValueObject\Sender::getFormatted
|
||||||
|
*/
|
||||||
|
public function testGetFormatted()
|
||||||
|
{
|
||||||
|
$this->assertSame(
|
||||||
|
'4915123456789',
|
||||||
|
$this->callMethod(
|
||||||
|
$this->sender,
|
||||||
|
'getFormatted'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,6 +53,7 @@ class SmsBinaryMessageTest extends ApiTestCase
|
|||||||
* @test
|
* @test
|
||||||
* @return void
|
* @return void
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\ValueObject\SmsBinaryMessage::__construct
|
||||||
*/
|
*/
|
||||||
public function testConstructValid()
|
public function testConstructValid()
|
||||||
{
|
{
|
||||||
@ -89,6 +90,7 @@ class SmsBinaryMessageTest extends ApiTestCase
|
|||||||
*
|
*
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
* @dataProvider constructInvalidDataProvider
|
* @dataProvider constructInvalidDataProvider
|
||||||
|
* @covers \D3\LinkmobilityClient\ValueObject\SmsBinaryMessage::__construct
|
||||||
*/
|
*/
|
||||||
public function testConstructInvalid($binaryMessage, $valid, $expectedException)
|
public function testConstructInvalid($binaryMessage, $valid, $expectedException)
|
||||||
{
|
{
|
||||||
@ -129,13 +131,14 @@ class SmsBinaryMessageTest extends ApiTestCase
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'empty message' => ['', true, InvalidArgumentException::class],
|
'empty message' => ['', true, InvalidArgumentException::class],
|
||||||
'invalid sms message' => ['abc', false, \Phlib\SmsLength\Exception\InvalidArgumentException::class]
|
'invalid sms message' => ['abc', false, \Phlib\SmsLength\Exception\InvalidArgumentException::class],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\ValueObject\SmsBinaryMessage::getSmsLength
|
||||||
*/
|
*/
|
||||||
public function testGetSmsLengthInstance()
|
public function testGetSmsLengthInstance()
|
||||||
{
|
{
|
||||||
@ -149,7 +152,9 @@ class SmsBinaryMessageTest extends ApiTestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\ValueObject\SmsBinaryMessage::chunkCount
|
||||||
*/
|
*/
|
||||||
public function testGetChunkCount()
|
public function testGetChunkCount()
|
||||||
{
|
{
|
||||||
@ -180,7 +185,9 @@ class SmsBinaryMessageTest extends ApiTestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\ValueObject\SmsBinaryMessage::length
|
||||||
*/
|
*/
|
||||||
public function testGetSize()
|
public function testGetSize()
|
||||||
{
|
{
|
||||||
@ -211,7 +218,10 @@ class SmsBinaryMessageTest extends ApiTestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\ValueObject\SmsBinaryMessage::getMessageContent
|
||||||
|
* @covers \D3\LinkmobilityClient\ValueObject\SmsMessageAbstract::getMessageContent
|
||||||
*/
|
*/
|
||||||
public function testGetMessageContent()
|
public function testGetMessageContent()
|
||||||
{
|
{
|
||||||
|
@ -42,6 +42,7 @@ class SmsTextMessageTest extends SmsBinaryMessageTest
|
|||||||
* @test
|
* @test
|
||||||
* @return void
|
* @return void
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\ValueObject\SmsTextMessage::__construct
|
||||||
*/
|
*/
|
||||||
public function testConstructValid()
|
public function testConstructValid()
|
||||||
{
|
{
|
||||||
@ -78,6 +79,7 @@ class SmsTextMessageTest extends SmsBinaryMessageTest
|
|||||||
*
|
*
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
* @dataProvider constructInvalidDataProvider
|
* @dataProvider constructInvalidDataProvider
|
||||||
|
* @covers \D3\LinkmobilityClient\ValueObject\SmsTextMessage::__construct
|
||||||
*/
|
*/
|
||||||
public function testConstructInvalid($binaryMessage, $valid, $expectedException)
|
public function testConstructInvalid($binaryMessage, $valid, $expectedException)
|
||||||
{
|
{
|
||||||
|
83
Tests/ValueObject/ValueObjectTest.php
Normal file
83
Tests/ValueObject/ValueObjectTest.php
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
<?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\ValueObject;
|
||||||
|
use libphonenumber\PhoneNumberFormat;
|
||||||
|
use libphonenumber\PhoneNumberType;
|
||||||
|
use libphonenumber\PhoneNumberUtil;
|
||||||
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
|
use ReflectionException;
|
||||||
|
|
||||||
|
class ValueObjectTest extends ApiTestCase
|
||||||
|
{
|
||||||
|
public function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
/** @var ValueObject|MockObject value */
|
||||||
|
$this->value = $this->getMockBuilder(ValueObject::class)
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->getMock();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @return void
|
||||||
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\ValueObject\ValueObject::__construct
|
||||||
|
* @covers \D3\LinkmobilityClient\ValueObject\ValueObject::get
|
||||||
|
*/
|
||||||
|
public function testConstructValid()
|
||||||
|
{
|
||||||
|
$phoneUtil = PhoneNumberUtil::getInstance();
|
||||||
|
$example = $phoneUtil->getExampleNumberForType('DE', PhoneNumberType::MOBILE);
|
||||||
|
$phoneNumberFixture = $phoneUtil->format($example, PhoneNumberFormat::NATIONAL);
|
||||||
|
|
||||||
|
$this->callMethod(
|
||||||
|
$this->value,
|
||||||
|
'__construct',
|
||||||
|
[$phoneNumberFixture]
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertSame(
|
||||||
|
'01512 3456789',
|
||||||
|
$this->getValue(
|
||||||
|
$this->value,
|
||||||
|
'value'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @return void
|
||||||
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\ValueObject\ValueObject::__construct
|
||||||
|
*/
|
||||||
|
public function testConstructInvalid()
|
||||||
|
{
|
||||||
|
$this->expectException(InvalidArgumentException::class);
|
||||||
|
|
||||||
|
$this->callMethod(
|
||||||
|
$this->value,
|
||||||
|
'__construct',
|
||||||
|
['']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -21,18 +21,18 @@
|
|||||||
"GPL-3.0-or-later"
|
"GPL-3.0-or-later"
|
||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^7.0 || ^8.0",
|
"php": "^7.3 || ^8.0",
|
||||||
"beberlei/assert": "^2.9.9",
|
"beberlei/assert": "^3.3",
|
||||||
"guzzlehttp/guzzle": "~6.2 || ^7.4",
|
"guzzlehttp/guzzle": "^7.4",
|
||||||
"psr/http-message": "~1.0",
|
"psr/http-message": "~1.0",
|
||||||
"phlib/sms-length": "^1.1.0 || ^2.0.0",
|
"phlib/sms-length": "^2.0",
|
||||||
"giggsey/libphonenumber-for-php": "^8.12.50",
|
"giggsey/libphonenumber-for-php": "^8.12.50",
|
||||||
"ext-json": "*"
|
"ext-json": "*"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"php": "^7.2",
|
"php": "^7.4",
|
||||||
"phpunit/phpunit" : "^8.0",
|
"phpunit/phpunit" : "^9.5",
|
||||||
"friendsofphp/php-cs-fixer": "^2.0"
|
"friendsofphp/php-cs-fixer": "^3.9"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
|
40
phpunit.xml
40
phpunit.xml
@ -1,22 +1,20 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
<phpunit
|
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
bootstrap="vendor/autoload.php"
|
bootstrap="vendor/autoload.php"
|
||||||
convertErrorsToExceptions="true"
|
convertErrorsToExceptions="true"
|
||||||
convertNoticesToExceptions="true"
|
convertNoticesToExceptions="true"
|
||||||
convertWarningsToExceptions="true">
|
convertWarningsToExceptions="true"
|
||||||
|
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
|
||||||
<testsuite name="tankerkoenig">
|
<coverage>
|
||||||
<directory>./Tests</directory>
|
<include>
|
||||||
</testsuite>
|
<directory suffix=".php">src</directory>
|
||||||
|
</include>
|
||||||
<filter>
|
<report>
|
||||||
<whitelist>
|
<clover outputFile="build/logs/clover.xml"/>
|
||||||
<directory suffix=".php">src</directory>
|
</report>
|
||||||
</whitelist>
|
</coverage>
|
||||||
</filter>
|
<testsuite name="linkmobility">
|
||||||
|
<directory>./Tests</directory>
|
||||||
<logging>
|
</testsuite>
|
||||||
<log type="coverage-clover" target="build/logs/clover.xml"/>
|
<logging/>
|
||||||
</logging>
|
|
||||||
|
|
||||||
</phpunit>
|
</phpunit>
|
||||||
|
@ -23,7 +23,7 @@ class LoggerHandler
|
|||||||
private static $instance = null;
|
private static $instance = null;
|
||||||
private $logger;
|
private $logger;
|
||||||
|
|
||||||
public static function getInstance()
|
public static function getInstance(): ?LoggerHandler
|
||||||
{
|
{
|
||||||
if (self::$instance === null) {
|
if (self::$instance === null) {
|
||||||
self::$instance = new self();
|
self::$instance = new self();
|
||||||
|
@ -16,13 +16,8 @@ declare(strict_types=1);
|
|||||||
namespace D3\LinkmobilityClient\RecipientsList;
|
namespace D3\LinkmobilityClient\RecipientsList;
|
||||||
|
|
||||||
use D3\LinkmobilityClient\Client;
|
use D3\LinkmobilityClient\Client;
|
||||||
use D3\LinkmobilityClient\Exceptions\ExceptionMessages;
|
|
||||||
use D3\LinkmobilityClient\Exceptions\RecipientException;
|
|
||||||
use D3\LinkmobilityClient\ValueObject\Recipient;
|
use D3\LinkmobilityClient\ValueObject\Recipient;
|
||||||
use Iterator;
|
use Iterator;
|
||||||
use libphonenumber\NumberParseException;
|
|
||||||
use libphonenumber\PhoneNumberType;
|
|
||||||
use libphonenumber\PhoneNumberUtil;
|
|
||||||
|
|
||||||
class RecipientsList implements RecipientsListInterface, Iterator
|
class RecipientsList implements RecipientsListInterface, Iterator
|
||||||
{
|
{
|
||||||
@ -41,14 +36,6 @@ class RecipientsList implements RecipientsListInterface, Iterator
|
|||||||
$this->setClient($client);
|
$this->setClient($client);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return PhoneNumberUtil
|
|
||||||
*/
|
|
||||||
protected function getPhoneNumberUtil(): PhoneNumberUtil
|
|
||||||
{
|
|
||||||
return PhoneNumberUtil::getInstance();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Recipient $recipient
|
* @param Recipient $recipient
|
||||||
*
|
*
|
||||||
@ -56,30 +43,7 @@ class RecipientsList implements RecipientsListInterface, Iterator
|
|||||||
*/
|
*/
|
||||||
public function add(Recipient $recipient): RecipientsListInterface
|
public function add(Recipient $recipient): RecipientsListInterface
|
||||||
{
|
{
|
||||||
$phoneUtil = $this->getPhoneNumberUtil();
|
$this->recipients[ md5(serialize($recipient)) ] = $recipient;
|
||||||
try {
|
|
||||||
$phoneNumber = $phoneUtil->parse($recipient->get(), $recipient->getCountryCode());
|
|
||||||
|
|
||||||
if (false === $phoneUtil->isValidNumber($phoneNumber)) {
|
|
||||||
throw new RecipientException(ExceptionMessages::INVALID_RECIPIENT_PHONE);
|
|
||||||
} elseif (
|
|
||||||
false === in_array(
|
|
||||||
$phoneUtil->getNumberType($phoneNumber),
|
|
||||||
[
|
|
||||||
PhoneNumberType::MOBILE,
|
|
||||||
PhoneNumberType::FIXED_LINE_OR_MOBILE
|
|
||||||
]
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
throw new RecipientException(ExceptionMessages::NOT_A_MOBILE_NUMBER);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->recipients[ md5(serialize($recipient)) ] = $recipient;
|
|
||||||
} catch (NumberParseException $e) {
|
|
||||||
$this->client->getLoggerHandler()->getLogger()->info($e->getMessage(), [$recipient]);
|
|
||||||
} catch (RecipientException $e) {
|
|
||||||
$this->client->getLoggerHandler()->getLogger()->info($e->getMessage(), [$recipient]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
@ -169,7 +169,7 @@ abstract class Request implements RequestInterface
|
|||||||
'senderAddress' => $this->getSenderAddress() ? $this->getSenderAddress()->getFormatted() : null,
|
'senderAddress' => $this->getSenderAddress() ? $this->getSenderAddress()->getFormatted() : null,
|
||||||
'senderAddressType' => $this->getSenderAddressType(),
|
'senderAddressType' => $this->getSenderAddressType(),
|
||||||
'test' => $this->getTestMode(),
|
'test' => $this->getTestMode(),
|
||||||
'validityPeriode' => $this->getValidityPeriode()
|
'validityPeriode' => $this->getValidityPeriode(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,7 +200,7 @@ abstract class Request implements RequestInterface
|
|||||||
'headers' => [
|
'headers' => [
|
||||||
'Accept' => $this->contentType,
|
'Accept' => $this->contentType,
|
||||||
'Content-Type' => $this->contentType,
|
'Content-Type' => $this->contentType,
|
||||||
]
|
],
|
||||||
],
|
],
|
||||||
$this->getBody()
|
$this->getBody()
|
||||||
);
|
);
|
||||||
@ -280,7 +280,7 @@ abstract class Request implements RequestInterface
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getClientMessageId()
|
public function getClientMessageId(): ?string
|
||||||
{
|
{
|
||||||
return $this->clientMessageId;
|
return $this->clientMessageId;
|
||||||
}
|
}
|
||||||
@ -306,7 +306,7 @@ abstract class Request implements RequestInterface
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
RequestInterface::CONTENTCATEGORY_ADVERTISEMENT => RequestInterface::CONTENTCATEGORY_ADVERTISEMENT,
|
RequestInterface::CONTENTCATEGORY_ADVERTISEMENT => RequestInterface::CONTENTCATEGORY_ADVERTISEMENT,
|
||||||
RequestInterface::CONTENTCATEGORY_INFORMATIONAL => RequestInterface::CONTENTCATEGORY_INFORMATIONAL
|
RequestInterface::CONTENTCATEGORY_INFORMATIONAL => RequestInterface::CONTENTCATEGORY_INFORMATIONAL,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -376,7 +376,7 @@ abstract class Request implements RequestInterface
|
|||||||
/**
|
/**
|
||||||
* @return string|null
|
* @return string|null
|
||||||
*/
|
*/
|
||||||
public function getNotificationCallbackUrl()
|
public function getNotificationCallbackUrl(): ?string
|
||||||
{
|
{
|
||||||
return $this->notificationCallbackUrl;
|
return $this->notificationCallbackUrl;
|
||||||
}
|
}
|
||||||
@ -396,7 +396,7 @@ abstract class Request implements RequestInterface
|
|||||||
/**
|
/**
|
||||||
* @return int|null
|
* @return int|null
|
||||||
*/
|
*/
|
||||||
public function getPriority()
|
public function getPriority(): ?int
|
||||||
{
|
{
|
||||||
return $this->priority;
|
return $this->priority;
|
||||||
}
|
}
|
||||||
@ -444,7 +444,7 @@ abstract class Request implements RequestInterface
|
|||||||
/**
|
/**
|
||||||
* @return Sender|null
|
* @return Sender|null
|
||||||
*/
|
*/
|
||||||
public function getSenderAddress()
|
public function getSenderAddress(): ?Sender
|
||||||
{
|
{
|
||||||
return $this->senderAddress;
|
return $this->senderAddress;
|
||||||
}
|
}
|
||||||
@ -464,7 +464,7 @@ abstract class Request implements RequestInterface
|
|||||||
/**
|
/**
|
||||||
* @return string|null
|
* @return string|null
|
||||||
*/
|
*/
|
||||||
public function getSenderAddressType()
|
public function getSenderAddressType(): ?string
|
||||||
{
|
{
|
||||||
return $this->getSenderAddress() && $this->getSenderAddress()->get() ? $this->senderAddressType : null;
|
return $this->getSenderAddress() && $this->getSenderAddress()->get() ? $this->senderAddressType : null;
|
||||||
}
|
}
|
||||||
@ -478,7 +478,7 @@ abstract class Request implements RequestInterface
|
|||||||
RequestInterface::SENDERADDRESSTYPE_ALPHANUMERIC => RequestInterface::SENDERADDRESSTYPE_ALPHANUMERIC,
|
RequestInterface::SENDERADDRESSTYPE_ALPHANUMERIC => RequestInterface::SENDERADDRESSTYPE_ALPHANUMERIC,
|
||||||
RequestInterface::SENDERADDRESSTYPE_INTERNATIONAL => RequestInterface::SENDERADDRESSTYPE_INTERNATIONAL,
|
RequestInterface::SENDERADDRESSTYPE_INTERNATIONAL => RequestInterface::SENDERADDRESSTYPE_INTERNATIONAL,
|
||||||
RequestInterface::SENDERADDRESSTYPE_NATIONAL => RequestInterface::SENDERADDRESSTYPE_NATIONAL,
|
RequestInterface::SENDERADDRESSTYPE_NATIONAL => RequestInterface::SENDERADDRESSTYPE_NATIONAL,
|
||||||
RequestInterface::SENDERADDRESSTYPE_SHORTCODE => RequestInterface::SENDERADDRESSTYPE_SHORTCODE
|
RequestInterface::SENDERADDRESSTYPE_SHORTCODE => RequestInterface::SENDERADDRESSTYPE_SHORTCODE,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -497,7 +497,7 @@ abstract class Request implements RequestInterface
|
|||||||
/**
|
/**
|
||||||
* @return int|null
|
* @return int|null
|
||||||
*/
|
*/
|
||||||
public function getValidityPeriode()
|
public function getValidityPeriode(): ?int
|
||||||
{
|
{
|
||||||
return $this->validityPeriode;
|
return $this->validityPeriode;
|
||||||
}
|
}
|
||||||
@ -523,6 +523,7 @@ abstract class Request implements RequestInterface
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Client $client
|
* @param Client $client
|
||||||
|
* @return Request
|
||||||
*/
|
*/
|
||||||
public function setClient(Client $client): Request
|
public function setClient(Client $client): Request
|
||||||
{
|
{
|
||||||
|
@ -72,7 +72,7 @@ abstract class Response implements ResponseInterface
|
|||||||
/**
|
/**
|
||||||
* @return string|null
|
* @return string|null
|
||||||
*/
|
*/
|
||||||
public function getClientMessageId()
|
public function getClientMessageId(): ?string
|
||||||
{
|
{
|
||||||
return $this->getContent()[self::CLIENTMESSAGEID];
|
return $this->getContent()[self::CLIENTMESSAGEID];
|
||||||
}
|
}
|
||||||
@ -80,13 +80,13 @@ abstract class Response implements ResponseInterface
|
|||||||
/**
|
/**
|
||||||
* @return string|null
|
* @return string|null
|
||||||
*/
|
*/
|
||||||
public function getTransferId()
|
public function getTransferId(): ?string
|
||||||
{
|
{
|
||||||
return $this->getContent()[self::TRANSFERID];
|
return $this->getContent()[self::TRANSFERID];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string|null
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function getSmsCount(): int
|
public function getSmsCount(): int
|
||||||
{
|
{
|
||||||
|
@ -36,7 +36,7 @@ class BinaryRequest extends Request implements SmsRequestInterface
|
|||||||
return array_merge(
|
return array_merge(
|
||||||
parent::getRawBody(),
|
parent::getRawBody(),
|
||||||
[
|
[
|
||||||
'userDataHeaderPresent' => true
|
'userDataHeaderPresent' => true,
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -20,21 +20,15 @@ use D3\LinkmobilityClient\ValueObject\SmsBinaryMessage;
|
|||||||
use D3\LinkmobilityClient\ValueObject\SmsTextMessage;
|
use D3\LinkmobilityClient\ValueObject\SmsTextMessage;
|
||||||
use Phlib\SmsLength\SmsLength;
|
use Phlib\SmsLength\SmsLength;
|
||||||
|
|
||||||
class RequestFactory
|
class RequestFactory implements RequestFactoryInterface
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @deprecated is SmsLength constant from version 2.1
|
|
||||||
*/
|
|
||||||
public const GSM_7BIT = '7-bit';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated is SmsLength constant from version 2.1
|
|
||||||
*/
|
|
||||||
public const GSM_UCS2 = 'ucs-2';
|
|
||||||
|
|
||||||
protected $message;
|
protected $message;
|
||||||
protected $client;
|
protected $client;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $message
|
||||||
|
* @param Client $client
|
||||||
|
*/
|
||||||
public function __construct($message, Client $client)
|
public function __construct($message, Client $client)
|
||||||
{
|
{
|
||||||
$this->message = $message;
|
$this->message = $message;
|
||||||
@ -46,7 +40,7 @@ class RequestFactory
|
|||||||
*/
|
*/
|
||||||
public function getSmsRequest(): SmsRequestInterface
|
public function getSmsRequest(): SmsRequestInterface
|
||||||
{
|
{
|
||||||
if ($this->getSmsLength()->getEncoding() === self::GSM_7BIT) {
|
if ($this->getSmsLength()->getEncoding() === SmsLength::ENCODING_7BIT) {
|
||||||
$message = new SmsTextMessage($this->message);
|
$message = new SmsTextMessage($this->message);
|
||||||
return new TextRequest($message, $this->client);
|
return new TextRequest($message, $this->client);
|
||||||
}
|
}
|
||||||
|
@ -15,9 +15,11 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace D3\LinkmobilityClient\SMS;
|
namespace D3\LinkmobilityClient\SMS;
|
||||||
|
|
||||||
|
use D3\LinkmobilityClient\Client;
|
||||||
|
|
||||||
interface RequestFactoryInterface
|
interface RequestFactoryInterface
|
||||||
{
|
{
|
||||||
public function __construct($message);
|
public function __construct($message, Client $client);
|
||||||
|
|
||||||
public function getRequest(): SmsRequestInterface;
|
public function getSmsRequest(): SmsRequestInterface;
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,8 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace D3\LinkmobilityClient\SMS;
|
namespace D3\LinkmobilityClient\SMS;
|
||||||
|
|
||||||
class Response extends \D3\LinkmobilityClient\Response\Response
|
use D3\LinkmobilityClient\Response\Response as BaseResponse;
|
||||||
|
|
||||||
|
class Response extends BaseResponse
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ class Url implements UrlInterface
|
|||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getTextSmsUri()
|
public function getTextSmsUri(): string
|
||||||
{
|
{
|
||||||
return '/rest/smsmessaging/text';
|
return '/rest/smsmessaging/text';
|
||||||
}
|
}
|
||||||
@ -38,7 +38,7 @@ class Url implements UrlInterface
|
|||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getBinarySmsUri()
|
public function getBinarySmsUri(): string
|
||||||
{
|
{
|
||||||
return '/rest/smsmessaging/binary';
|
return '/rest/smsmessaging/binary';
|
||||||
}
|
}
|
||||||
|
@ -18,4 +18,8 @@ namespace D3\LinkmobilityClient\Url;
|
|||||||
interface UrlInterface
|
interface UrlInterface
|
||||||
{
|
{
|
||||||
public function getBaseUri(): string;
|
public function getBaseUri(): string;
|
||||||
|
|
||||||
|
public function getTextSmsUri(): string;
|
||||||
|
|
||||||
|
public function getBinarySmsUri(): string;
|
||||||
}
|
}
|
||||||
|
@ -16,12 +16,23 @@ declare(strict_types=1);
|
|||||||
namespace D3\LinkmobilityClient\ValueObject;
|
namespace D3\LinkmobilityClient\ValueObject;
|
||||||
|
|
||||||
use Assert\Assert;
|
use Assert\Assert;
|
||||||
|
use D3\LinkmobilityClient\Exceptions\ExceptionMessages;
|
||||||
|
use D3\LinkmobilityClient\Exceptions\RecipientException;
|
||||||
use libphonenumber\NumberParseException;
|
use libphonenumber\NumberParseException;
|
||||||
use libphonenumber\PhoneNumberFormat;
|
use libphonenumber\PhoneNumberFormat;
|
||||||
|
use libphonenumber\PhoneNumberType;
|
||||||
use libphonenumber\PhoneNumberUtil;
|
use libphonenumber\PhoneNumberUtil;
|
||||||
|
|
||||||
class Recipient extends StringValueObject
|
class Recipient extends StringValueObject
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $allowedNumberTypes = [
|
||||||
|
PhoneNumberType::MOBILE,
|
||||||
|
PhoneNumberType::FIXED_LINE_OR_MOBILE,
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
@ -32,9 +43,11 @@ class Recipient extends StringValueObject
|
|||||||
* @param string $iso2CountryCode
|
* @param string $iso2CountryCode
|
||||||
*
|
*
|
||||||
* @throws NumberParseException
|
* @throws NumberParseException
|
||||||
|
* @throws RecipientException
|
||||||
*/
|
*/
|
||||||
public function __construct(string $number, string $iso2CountryCode)
|
public function __construct(string $number, string $iso2CountryCode)
|
||||||
{
|
{
|
||||||
|
Assert::that($number)->notEmpty();
|
||||||
Assert::that($iso2CountryCode)->string()->length(2);
|
Assert::that($iso2CountryCode)->string()->length(2);
|
||||||
|
|
||||||
$phoneUtil = $this->getPhoneNumberUtil();
|
$phoneUtil = $this->getPhoneNumberUtil();
|
||||||
@ -42,6 +55,17 @@ class Recipient extends StringValueObject
|
|||||||
$phoneNumber = $phoneUtil->parse($number, strtoupper($iso2CountryCode));
|
$phoneNumber = $phoneUtil->parse($number, strtoupper($iso2CountryCode));
|
||||||
$number = $phoneUtil->format($phoneNumber, PhoneNumberFormat::E164);
|
$number = $phoneUtil->format($phoneNumber, PhoneNumberFormat::E164);
|
||||||
|
|
||||||
|
if (false === $phoneUtil->isValidNumber($phoneNumber)) {
|
||||||
|
throw new RecipientException(ExceptionMessages::INVALID_RECIPIENT_PHONE);
|
||||||
|
} elseif (
|
||||||
|
false === in_array(
|
||||||
|
$phoneUtil->getNumberType($phoneNumber),
|
||||||
|
$this->allowedNumberTypes
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
throw new RecipientException(ExceptionMessages::NOT_A_MOBILE_NUMBER);
|
||||||
|
}
|
||||||
|
|
||||||
parent::__construct($number);
|
parent::__construct($number);
|
||||||
$this->countryCode = $iso2CountryCode;
|
$this->countryCode = $iso2CountryCode;
|
||||||
}
|
}
|
||||||
@ -62,7 +86,7 @@ class Recipient extends StringValueObject
|
|||||||
return $this->countryCode;
|
return $this->countryCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFormatted()
|
public function getFormatted(): string
|
||||||
{
|
{
|
||||||
return ltrim(parent::getFormatted(), '+');
|
return ltrim(parent::getFormatted(), '+');
|
||||||
}
|
}
|
||||||
|
@ -27,11 +27,11 @@ use libphonenumber\PhoneNumberUtil;
|
|||||||
class Sender extends ValueObject
|
class Sender extends ValueObject
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @param string $number
|
* @param string|null $number
|
||||||
* @param string $iso2CountryCode
|
* @param string|null $iso2CountryCode
|
||||||
*
|
*
|
||||||
* @throws RecipientException
|
|
||||||
* @throws NumberParseException
|
* @throws NumberParseException
|
||||||
|
* @throws RecipientException
|
||||||
*/
|
*/
|
||||||
public function __construct(string $number = null, string $iso2CountryCode = null)
|
public function __construct(string $number = null, string $iso2CountryCode = null)
|
||||||
{
|
{
|
||||||
@ -67,7 +67,7 @@ class Sender extends ValueObject
|
|||||||
return PhoneNumberUtil::getInstance();
|
return PhoneNumberUtil::getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFormatted()
|
public function getFormatted(): string
|
||||||
{
|
{
|
||||||
return ltrim(parent::getFormatted(), '+');
|
return ltrim(parent::getFormatted(), '+');
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ class SmsBinaryMessage extends SmsMessageAbstract
|
|||||||
public function getMessageContent()
|
public function getMessageContent()
|
||||||
{
|
{
|
||||||
return str_split(
|
return str_split(
|
||||||
base64_encode($this->get()),
|
base64_encode(parent::getMessageContent()),
|
||||||
SmsLength::MAXIMUM_CHARACTERS_UCS2_SINGLE
|
SmsLength::MAXIMUM_CHARACTERS_UCS2_SINGLE
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -43,6 +43,9 @@ abstract class SmsMessageAbstract extends StringValueObject implements SmsMessag
|
|||||||
return $this->getSmsLength()->getSize();
|
return $this->getSmsLength()->getSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
public function getMessageContent()
|
public function getMessageContent()
|
||||||
{
|
{
|
||||||
return $this->get();
|
return $this->get();
|
||||||
|
@ -15,8 +15,6 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace D3\LinkmobilityClient\ValueObject;
|
namespace D3\LinkmobilityClient\ValueObject;
|
||||||
|
|
||||||
use Assert\Assert;
|
|
||||||
|
|
||||||
abstract class StringValueObject extends ValueObject
|
abstract class StringValueObject extends ValueObject
|
||||||
{
|
{
|
||||||
public function __toString()
|
public function __toString()
|
||||||
|
@ -33,7 +33,7 @@ abstract class ValueObject
|
|||||||
return $this->value;
|
return $this->value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFormatted()
|
public function getFormatted(): string
|
||||||
{
|
{
|
||||||
return $this->get();
|
return $this->get();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user