Compare commits
26 Commits
Author | SHA1 | Date | |
---|---|---|---|
1d5ccb6d73
|
|||
4f3b1029f4
|
|||
f4d5e54448
|
|||
4cd0ab0d17
|
|||
1a9389d763
|
|||
491c260870
|
|||
50d2276a78
|
|||
b22da1bd4a
|
|||
95b95d1d8b
|
|||
d0db444157
|
|||
096ef7ed05
|
|||
dc0b680776
|
|||
05ff18d537
|
|||
05132f82ee
|
|||
f5579d9d5e
|
|||
4e5147a0ac
|
|||
23de1d2f06
|
|||
73694a1c57
|
|||
fe60f1102d
|
|||
7e67bc1818
|
|||
aa88f09e16
|
|||
f1eae3bd87
|
|||
bd9c3e6c03
|
|||
5cbbc8295f
|
|||
621ea0ebe9
|
|||
9ef121ef01
|
52
CHANGELOG.md
52
CHANGELOG.md
@ -1,10 +1,56 @@
|
||||
# Changelog
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
---
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## 1.0.0.0 (2022-07-13)
|
||||
## [Unreleased](https://git.d3data.de/D3Private/linkmobility-php-client/compare/1.3.2...rel_1.x)
|
||||
|
||||
## [1.3.2](https://git.d3data.de/D3Private/linkmobility-php-client/compare/1.3.1...1.3.2) - 2022-07-28
|
||||
### Changed
|
||||
- add support note
|
||||
- adjust readme
|
||||
|
||||
## [1.3.1](https://git.d3data.de/D3Private/linkmobility-php-client/compare/1.3.0...1.3.1) - 2022-07-28
|
||||
### Changed
|
||||
- improve code quality
|
||||
|
||||
### Fixed
|
||||
- wrong return type of LoggerHandler::getInstance
|
||||
|
||||
## [1.3.0](https://git.d3data.de/D3Private/linkmobility-php-client/compare/1.2.1...1.3.0) - 2022-07-18
|
||||
### Added
|
||||
- tests added
|
||||
|
||||
### Changed
|
||||
- tests use generated example phone numbers
|
||||
- move recipient checks from list to recipient itself
|
||||
|
||||
## [1.2.1](https://git.d3data.de/D3Private/linkmobility-php-client/compare/1.2.0...1.2.1) - 2022-07-15
|
||||
### Changed
|
||||
- extend log messages
|
||||
- sanitize special phone number format before request
|
||||
|
||||
## [1.2.0](https://git.d3data.de/D3Private/linkmobility-php-client/compare/1.1.0...1.2.0) - 2022-07-14
|
||||
### Added
|
||||
- collect exception messages in a class
|
||||
- collect URI parts in a class
|
||||
|
||||
### Changed
|
||||
- make sender number optional
|
||||
- assign sender address type only if sender is set
|
||||
- extract logger handler from client
|
||||
|
||||
## [1.1.0](https://git.d3data.de/D3Private/linkmobility-php-client/compare/1.0.0...1.1.0) - 2022-07-13
|
||||
### Added
|
||||
- make installable in PHP 8
|
||||
|
||||
### Removed
|
||||
- remove unused dependency
|
||||
|
||||
## [1.0.0](https://git.d3data.de/D3Private/linkmobility-php-client/releases/tag/1.0.0) - 2022-07-13
|
||||
### Added
|
||||
- initial implementation
|
||||
- SMS requests (text or binary)
|
||||
- SMS responses
|
||||
- recipient managing
|
||||
- recipient managing
|
||||
|
@ -1,7 +1,7 @@
|
||||
[](README.md)
|
||||
[](README.en.md)
|
||||
|
||||
# LINK Mobility Austria PHP API Client
|
||||
# LINK Mobility PHP API Client
|
||||
|
||||
[LINK Mobility](https://www.linkmobility.de/) provides a service for sending mobile messages (SMS, Whatsapp, RCS, Chatbot, ...).
|
||||
|
||||
@ -39,6 +39,12 @@ If you have a suggestion that would make this better, please fork the repo and c
|
||||
- Push to the Branch (git push origin feature/AmazingFeature)
|
||||
- Open a Pull Request
|
||||
|
||||
## Support
|
||||
|
||||
If you have any questions about the *messaging service* and its *contracts*, please contact the [LINK Mobility Team](https://www.linkmobility.de/kontakt).
|
||||
|
||||
For *technical inquiries* you will find the contact options in the [composer.json](composer.json).
|
||||
|
||||
## License
|
||||
(status: 2022-07-13)
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
[](README.md)
|
||||
[](README.en.md)
|
||||
|
||||
# LINK Mobility Austria PHP API Client
|
||||
# LINK Mobility PHP API Client
|
||||
|
||||
[LINK Mobility](https://www.linkmobility.de/) stellt einen Service zum Versenden von mobilen Nachrichten (SMS, Whatsapp, RCS, Chatbot, ...) zur VerfĂĽgung.
|
||||
|
||||
@ -39,6 +39,12 @@ Wenn Sie eine Verbesserungsvorschlag haben, legen Sie einen Fork des Respoitorie
|
||||
- Ăśbertragen Sie den Branch (git push origin feature/AmazingFeature)
|
||||
- Ă–ffnen Sie einen Pull Request
|
||||
|
||||
## Support
|
||||
|
||||
Bei Fragen zum *Messaging Service* und dessen *Verträgen* kontaktieren Sie bitte das [LINK Mobility Team](https://www.linkmobility.de/kontakt).
|
||||
|
||||
Zu *technischen Anfragen* finden Sie die Kontaktmöglichkeiten in der [composer.json](composer.json).
|
||||
|
||||
## Lizenz
|
||||
(Stand: 13.07.2022)
|
||||
|
||||
|
104
Tests/ALoggerHandlerTest.php
Normal file
104
Tests/ALoggerHandlerTest.php
Normal file
@ -0,0 +1,104 @@
|
||||
<?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;
|
||||
|
||||
use D3\LinkmobilityClient\LoggerHandler;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Psr\Log\AbstractLogger;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use ReflectionException;
|
||||
|
||||
class ALoggerHandlerTest extends ApiTestCase
|
||||
{
|
||||
/** tests must run as first, because of singleton, which must not initialized before */
|
||||
|
||||
/** @var LoggerHandler */
|
||||
public $loggerHandler;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->loggerHandler = new LoggerHandler();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
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
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LinkmobilityClient\LoggerHandler::__construct
|
||||
*/
|
||||
public function testConstruct()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
LoggerInterface::class,
|
||||
$this->callMethod($this->loggerHandler, 'getLogger')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LinkmobilityClient\LoggerHandler::setLogger
|
||||
* @covers \D3\LinkmobilityClient\LoggerHandler::getLogger
|
||||
*/
|
||||
public function testLogger()
|
||||
{
|
||||
/** @var LoggerInterface|MockObject $loggerMock */
|
||||
$loggerMock = $this->getMockBuilder(AbstractLogger::class)
|
||||
->onlyMethods(['debug', 'error', 'log'])
|
||||
->getMock();
|
||||
|
||||
$this->callMethod($this->loggerHandler, 'setLogger', [ $loggerMock]);
|
||||
$this->assertSame(
|
||||
$loggerMock,
|
||||
$this->callMethod($this->loggerHandler, 'getLogger')
|
||||
);
|
||||
}
|
||||
}
|
@ -18,12 +18,13 @@ namespace D3\LinkmobilityClient\Tests;
|
||||
use Assert\InvalidArgumentException;
|
||||
use D3\LinkmobilityClient\Client;
|
||||
use D3\LinkmobilityClient\Exceptions\ApiException;
|
||||
use D3\LinkmobilityClient\LoggerHandler;
|
||||
use D3\LinkmobilityClient\Request\RequestInterface;
|
||||
use D3\LinkmobilityClient\Response\Response;
|
||||
use D3\LinkmobilityClient\Response\ResponseInterface;
|
||||
use D3\LinkmobilityClient\SMS\TextRequest;
|
||||
use D3\LinkmobilityClient\Url;
|
||||
use D3\LinkmobilityClient\UrlInterface;
|
||||
use D3\LinkmobilityClient\Url\Url;
|
||||
use D3\LinkmobilityClient\Url\UrlInterface;
|
||||
use GuzzleHttp\Client as GuzzleClient;
|
||||
use GuzzleHttp\ClientInterface;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
@ -67,6 +68,7 @@ class ClientTest extends ApiTestCase
|
||||
* @param $apiClient
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LinkmobilityClient\Client::__construct
|
||||
*/
|
||||
public function testConstruct($apiKey, $apiUrl, $apiClient)
|
||||
{
|
||||
@ -103,6 +105,7 @@ class ClientTest extends ApiTestCase
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @dataProvider requestPassedDataProvider
|
||||
* @covers \D3\LinkmobilityClient\Client::request
|
||||
*
|
||||
*/
|
||||
public function testRequest($requestIsValid)
|
||||
@ -170,13 +173,13 @@ class ClientTest extends ApiTestCase
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @param $useLogger
|
||||
* @param $okStatus
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @dataProvider rawRequestDataProvider
|
||||
* @covers \D3\LinkmobilityClient\Client::rawRequest
|
||||
*/
|
||||
public function testRawRequest($useLogger, $okStatus)
|
||||
public function testRawRequest($okStatus)
|
||||
{
|
||||
$statusCode = $okStatus ? '200' : '301';
|
||||
|
||||
@ -205,7 +208,7 @@ class ClientTest extends ApiTestCase
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$responseMock->expects($this->atLeastOnce())->method('getStatusCode')->willReturn($statusCode);
|
||||
$responseMock->expects($useLogger && $okStatus ? $this->atLeastOnce() : $this->never())
|
||||
$responseMock->expects($this->atLeastOnce())
|
||||
->method('getBody')->willReturn($streamMock);
|
||||
|
||||
/** @var GuzzleClient|MockObject $requestClientMock */
|
||||
@ -219,17 +222,21 @@ class ClientTest extends ApiTestCase
|
||||
->onlyMethods(['debug', 'error', 'log'])
|
||||
->getMock();
|
||||
|
||||
/** @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([
|
||||
'hasLogger',
|
||||
'getLogger'
|
||||
'getLoggerHandler'
|
||||
])
|
||||
->getMock();
|
||||
$clientMock->method('hasLogger')->willReturn($useLogger);
|
||||
$clientMock->expects($useLogger ? $this->atLeastOnce() : $this->never())
|
||||
->method('getLogger')->willReturn($loggerMock);
|
||||
$clientMock->expects($this->atLeastOnce())
|
||||
->method('getLoggerHandler')->willReturn($loggerHandlerMock);
|
||||
$this->setValue($clientMock, 'requestClient', $requestClientMock);
|
||||
|
||||
if (false === $okStatus) {
|
||||
@ -247,10 +254,8 @@ class ClientTest extends ApiTestCase
|
||||
public function rawRequestDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'has logger, OK status' => [true, true],
|
||||
'has no logger, OK status' => [false, true],
|
||||
'has logger, NOK status' => [true, false],
|
||||
'has no logger, NOK status' => [false, false],
|
||||
'OK status' => [true],
|
||||
'NOK status' => [false],
|
||||
];
|
||||
}
|
||||
|
||||
@ -258,26 +263,16 @@ class ClientTest extends ApiTestCase
|
||||
* @test
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LinkmobilityClient\Client::getLoggerHandler
|
||||
*/
|
||||
public function testLogger()
|
||||
public function testGetLoggerHandler()
|
||||
{
|
||||
$this->assertFalse($this->callMethod($this->api, 'hasLogger'));
|
||||
$this->assertNull($this->callMethod($this->api, 'getLogger'));
|
||||
|
||||
/** @var LoggerInterface|MockObject $loggerMock */
|
||||
$loggerMock = $this->getMockBuilder(AbstractLogger::class)
|
||||
->onlyMethods(['debug', 'error', 'log'])
|
||||
->getMock();
|
||||
|
||||
$this->assertSame(
|
||||
$this->api,
|
||||
$this->callMethod($this->api, 'setLogger', [$loggerMock])
|
||||
);
|
||||
|
||||
$this->assertTrue($this->callMethod($this->api, 'hasLogger'));
|
||||
$this->assertSame(
|
||||
$loggerMock,
|
||||
$this->callMethod($this->api, 'getLogger')
|
||||
$this->assertInstanceOf(
|
||||
LoggerHandler::class,
|
||||
$this->callMethod(
|
||||
$this->api,
|
||||
'getLoggerHandler'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -19,13 +19,10 @@ use D3\LinkmobilityClient\Client;
|
||||
use D3\LinkmobilityClient\RecipientsList\RecipientsList;
|
||||
use D3\LinkmobilityClient\Tests\ApiTestCase;
|
||||
use D3\LinkmobilityClient\ValueObject\Recipient;
|
||||
use libphonenumber\NumberParseException;
|
||||
use libphonenumber\PhoneNumber;
|
||||
use libphonenumber\PhoneNumberFormat;
|
||||
use libphonenumber\PhoneNumberType;
|
||||
use libphonenumber\PhoneNumberUtil;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Psr\Log\AbstractLogger;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use ReflectionException;
|
||||
use stdClass;
|
||||
|
||||
@ -34,7 +31,7 @@ class RecipientsListTest extends ApiTestCase
|
||||
/** @var RecipientsList */
|
||||
public $recipientsList;
|
||||
|
||||
private $phoneNumberFixture = '01527565839';
|
||||
private $phoneNumberFixture;
|
||||
private $phoneCountryFixture = 'DE';
|
||||
|
||||
/**
|
||||
@ -50,6 +47,10 @@ class RecipientsListTest extends ApiTestCase
|
||||
->getMock();
|
||||
|
||||
$this->recipientsList = new RecipientsList($clientMock);
|
||||
|
||||
$phoneUtil = PhoneNumberUtil::getInstance();
|
||||
$example = $phoneUtil->getExampleNumberForType($this->phoneCountryFixture, PhoneNumberType::MOBILE);
|
||||
$this->phoneNumberFixture = $phoneUtil->format($example, PhoneNumberFormat::NATIONAL);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -65,6 +66,7 @@ class RecipientsListTest extends ApiTestCase
|
||||
/**
|
||||
* @test
|
||||
* @return void
|
||||
* @covers \D3\LinkmobilityClient\RecipientsList\RecipientsList::__construct
|
||||
*/
|
||||
public function testConstruct()
|
||||
{
|
||||
@ -84,33 +86,10 @@ class RecipientsListTest extends ApiTestCase
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function testGetPhoneNumberUtil()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
PhoneNumberUtil::class,
|
||||
$this->callMethod(
|
||||
$this->recipientsList,
|
||||
'getPhoneNumberUtil'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LinkmobilityClient\RecipientsList\RecipientsList::add
|
||||
*/
|
||||
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 */
|
||||
$recipientMock = $this->getMockBuilder(Recipient::class)
|
||||
->onlyMethods(['get', 'getCountryCode'])
|
||||
@ -119,15 +98,6 @@ class RecipientsListTest extends ApiTestCase
|
||||
$recipientMock->method('get')->willReturn($this->phoneNumberFixture);
|
||||
$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(
|
||||
0,
|
||||
$this->callMethod($this->recipientsList, 'getRecipientsList')
|
||||
@ -151,90 +121,8 @@ class RecipientsListTest extends ApiTestCase
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @dataProvider addInvalidNumberDataProvider
|
||||
*/
|
||||
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 Client|MockObject $clientMock */
|
||||
$clientMock = $this->getMockBuilder(Client::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods(['hasLogger', 'getLogger'])
|
||||
->getMock();
|
||||
$clientMock->method('hasLogger')->willReturn(true);
|
||||
$clientMock->method('getLogger')->willReturn($loggerMock);
|
||||
|
||||
/** @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
|
||||
* @covers \D3\LinkmobilityClient\RecipientsList\RecipientsList::clearRecipents
|
||||
* @covers \D3\LinkmobilityClient\RecipientsList\RecipientsList::getRecipientsList
|
||||
*/
|
||||
public function testClearRecipents()
|
||||
{
|
||||
@ -262,6 +150,7 @@ class RecipientsListTest extends ApiTestCase
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LinkmobilityClient\RecipientsList\RecipientsList::getRecipients
|
||||
*/
|
||||
public function testGetRecipients()
|
||||
{
|
||||
@ -290,6 +179,7 @@ class RecipientsListTest extends ApiTestCase
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LinkmobilityClient\RecipientsList\RecipientsList::getRecipientsList
|
||||
*/
|
||||
public function testGetRecipientsList()
|
||||
{
|
||||
@ -321,6 +211,10 @@ class RecipientsListTest extends ApiTestCase
|
||||
/**
|
||||
* @test
|
||||
* @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()
|
||||
{
|
||||
@ -369,6 +263,7 @@ class RecipientsListTest extends ApiTestCase
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LinkmobilityClient\RecipientsList\RecipientsList::valid
|
||||
*/
|
||||
public function testValid()
|
||||
{
|
||||
@ -400,13 +295,15 @@ class RecipientsListTest extends ApiTestCase
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LinkmobilityClient\RecipientsList\RecipientsList::setClient
|
||||
* @covers \D3\LinkmobilityClient\RecipientsList\RecipientsList::getClient
|
||||
*/
|
||||
public function testSetGetClient()
|
||||
{
|
||||
/** @var Client|MockObject $clientMock */
|
||||
$clientMock = $this->getMockBuilder(Client::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->assertInstanceOf(
|
||||
RecipientsList::class,
|
||||
|
@ -24,6 +24,9 @@ use D3\LinkmobilityClient\SMS\Response;
|
||||
use D3\LinkmobilityClient\Tests\ApiTestCase;
|
||||
use D3\LinkmobilityClient\ValueObject\Recipient;
|
||||
use D3\LinkmobilityClient\ValueObject\Sender;
|
||||
use libphonenumber\PhoneNumberFormat;
|
||||
use libphonenumber\PhoneNumberType;
|
||||
use libphonenumber\PhoneNumberUtil;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
@ -62,6 +65,8 @@ abstract class AbstractRequest extends ApiTestCase
|
||||
* @test
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::__construct
|
||||
* @covers \D3\LinkmobilityClient\SMS\TextRequest::__construct
|
||||
*/
|
||||
public function testConstruct()
|
||||
{
|
||||
@ -95,10 +100,33 @@ abstract class AbstractRequest extends ApiTestCase
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::getUri
|
||||
* @covers \D3\LinkmobilityClient\SMS\TextRequest::getUri
|
||||
*/
|
||||
public function testGetUri()
|
||||
{
|
||||
$this->assertIsString(
|
||||
$this->callMethod(
|
||||
$this->request,
|
||||
'getUri'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::validate
|
||||
* @covers \D3\LinkmobilityClient\SMS\TextRequest::validate
|
||||
* @covers \D3\LinkmobilityClient\Request\Request::validate
|
||||
*/
|
||||
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 */
|
||||
$requestMock = $this->getMockBuilder($this->testClassName)
|
||||
@ -122,10 +150,16 @@ abstract class AbstractRequest extends ApiTestCase
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::validate
|
||||
* @covers \D3\LinkmobilityClient\SMS\TextRequest::validate
|
||||
*/
|
||||
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 */
|
||||
$requestMock = $this->getMockBuilder($this->testClassName)
|
||||
@ -151,6 +185,9 @@ abstract class AbstractRequest extends ApiTestCase
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::getRawBody
|
||||
* @covers \D3\LinkmobilityClient\SMS\TextRequest::getRawBody
|
||||
* @covers \D3\LinkmobilityClient\Request\Request::getRawBody
|
||||
*/
|
||||
public function testGetRawBody()
|
||||
{
|
||||
@ -175,6 +212,8 @@ abstract class AbstractRequest extends ApiTestCase
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @dataProvider getBodyDataProvider
|
||||
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::getBody
|
||||
* @covers \D3\LinkmobilityClient\SMS\TextRequest::getBody
|
||||
*/
|
||||
public function testGetBody($contentType, $expected)
|
||||
{
|
||||
@ -228,11 +267,11 @@ abstract class AbstractRequest extends ApiTestCase
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::getOptions
|
||||
* @covers \D3\LinkmobilityClient\SMS\TextRequest::getOptions
|
||||
*/
|
||||
public function testGetOptions()
|
||||
{
|
||||
@ -292,6 +331,10 @@ abstract class AbstractRequest extends ApiTestCase
|
||||
/**
|
||||
* @test
|
||||
* @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()
|
||||
{
|
||||
@ -305,6 +348,10 @@ abstract class AbstractRequest extends ApiTestCase
|
||||
/**
|
||||
* @test
|
||||
* @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()
|
||||
{
|
||||
@ -314,6 +361,8 @@ abstract class AbstractRequest extends ApiTestCase
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::getMethods
|
||||
* @covers \D3\LinkmobilityClient\SMS\TextRequest::getMethods
|
||||
*/
|
||||
public function getMethodsTest()
|
||||
{
|
||||
@ -329,6 +378,10 @@ abstract class AbstractRequest extends ApiTestCase
|
||||
/**
|
||||
* @test
|
||||
* @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()
|
||||
{
|
||||
@ -338,6 +391,10 @@ abstract class AbstractRequest extends ApiTestCase
|
||||
/**
|
||||
* @test
|
||||
* @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()
|
||||
{
|
||||
@ -347,6 +404,10 @@ abstract class AbstractRequest extends ApiTestCase
|
||||
/**
|
||||
* @test
|
||||
* @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()
|
||||
{
|
||||
@ -356,6 +417,8 @@ abstract class AbstractRequest extends ApiTestCase
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::getContentCategories
|
||||
* @covers \D3\LinkmobilityClient\SMS\TextRequest::getContentCategories
|
||||
*/
|
||||
public function getContentCategoriesTest()
|
||||
{
|
||||
@ -371,6 +434,10 @@ abstract class AbstractRequest extends ApiTestCase
|
||||
/**
|
||||
* @test
|
||||
* @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()
|
||||
{
|
||||
@ -380,6 +447,10 @@ abstract class AbstractRequest extends ApiTestCase
|
||||
/**
|
||||
* @test
|
||||
* @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()
|
||||
{
|
||||
@ -389,6 +460,10 @@ abstract class AbstractRequest extends ApiTestCase
|
||||
/**
|
||||
* @test
|
||||
* @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()
|
||||
{
|
||||
@ -398,6 +473,10 @@ abstract class AbstractRequest extends ApiTestCase
|
||||
/**
|
||||
* @test
|
||||
* @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()
|
||||
{
|
||||
@ -407,6 +486,10 @@ abstract class AbstractRequest extends ApiTestCase
|
||||
/**
|
||||
* @test
|
||||
* @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()
|
||||
{
|
||||
@ -416,6 +499,8 @@ abstract class AbstractRequest extends ApiTestCase
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::getRecipientsList
|
||||
* @covers \D3\LinkmobilityClient\SMS\TextRequest::getRecipientsList
|
||||
*/
|
||||
public function getRecipientsListTest()
|
||||
{
|
||||
@ -431,6 +516,10 @@ abstract class AbstractRequest extends ApiTestCase
|
||||
/**
|
||||
* @test
|
||||
* @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()
|
||||
{
|
||||
@ -440,6 +529,10 @@ abstract class AbstractRequest extends ApiTestCase
|
||||
/**
|
||||
* @test
|
||||
* @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()
|
||||
{
|
||||
@ -453,15 +546,66 @@ abstract class AbstractRequest extends ApiTestCase
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @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 setGetSenderAddressTypeTest()
|
||||
public function testSetGetSenderAddressType($hasSender, $addressType, $expected)
|
||||
{
|
||||
$this->checkGetterSetter('fixture', 'setSenderAddressType', 'getSenderAddressType');
|
||||
/** @var Request|MockObject $request */
|
||||
$request = $this->getMockBuilder($this->testClassName)
|
||||
->setConstructorArgs([$this->request->getMessage(), $this->request->getClient()])
|
||||
->onlyMethods(['getSenderAddress'])
|
||||
->getMock();
|
||||
|
||||
if ($hasSender) {
|
||||
/** @var Sender|MockObject $senderMock */
|
||||
$senderMock = $this->getMockBuilder(Sender::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods(['get'])
|
||||
->getMock();
|
||||
$senderMock->method('get')->willReturn('fixture');
|
||||
$request->method('getSenderAddress')->willReturn($senderMock);
|
||||
} else {
|
||||
$request->method('getSenderAddress')->willReturn(null);
|
||||
}
|
||||
|
||||
$this->assertInstanceOf(
|
||||
Request::class,
|
||||
$this->callMethod(
|
||||
$request,
|
||||
'setSenderAddressType',
|
||||
[$addressType]
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertSame(
|
||||
$expected,
|
||||
$this->callMethod(
|
||||
$request,
|
||||
'getSenderAddressType'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array[]
|
||||
*/
|
||||
public function setGetSenderAddressTypeDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'has no sender' => [false, 'fixture', null],
|
||||
'has sender and address type' => [true, 'fixture', 'fixture'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::getSenderAddressTypes
|
||||
* @covers \D3\LinkmobilityClient\SMS\TextRequest::getSenderAddressTypes
|
||||
*/
|
||||
public function getSenderAddressTypesTest()
|
||||
{
|
||||
@ -477,6 +621,10 @@ abstract class AbstractRequest extends ApiTestCase
|
||||
/**
|
||||
* @test
|
||||
* @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()
|
||||
{
|
||||
@ -487,6 +635,8 @@ abstract class AbstractRequest extends ApiTestCase
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @dataProvider getResponseInstanceDataProvider
|
||||
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::getResponseInstance
|
||||
* @covers \D3\LinkmobilityClient\SMS\TextRequest::getResponseInstance
|
||||
*/
|
||||
public function testGetResponseInstance(ResponseInterface $response)
|
||||
{
|
||||
@ -542,6 +692,10 @@ abstract class AbstractRequest extends ApiTestCase
|
||||
/**
|
||||
* @test
|
||||
* @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()
|
||||
{
|
||||
@ -552,4 +706,33 @@ abstract class AbstractRequest extends ApiTestCase
|
||||
|
||||
$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,6 +29,9 @@ abstract class AbstractResponse extends ApiTestCase
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LinkmobilityClient\SMS\Response::__construct
|
||||
* @covers \D3\LinkmobilityClient\SMS\Response::getRawResponse
|
||||
* @covers \D3\LinkmobilityClient\SMS\Response::getContent
|
||||
*/
|
||||
public function testConstruct()
|
||||
{
|
||||
@ -102,6 +105,7 @@ abstract class AbstractResponse extends ApiTestCase
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LinkmobilityClient\SMS\Response::getInternalStatus
|
||||
*/
|
||||
public function testGetInternalStatus()
|
||||
{
|
||||
@ -111,6 +115,7 @@ abstract class AbstractResponse extends ApiTestCase
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LinkmobilityClient\SMS\Response::getStatusMessage
|
||||
*/
|
||||
public function testGetStatusMessage()
|
||||
{
|
||||
@ -120,6 +125,17 @@ abstract class AbstractResponse extends ApiTestCase
|
||||
/**
|
||||
* @test
|
||||
* @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()
|
||||
{
|
||||
@ -129,6 +145,7 @@ abstract class AbstractResponse extends ApiTestCase
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LinkmobilityClient\SMS\Response::getSmsCount
|
||||
*/
|
||||
public function testGetSmsCount()
|
||||
{
|
||||
@ -142,6 +159,7 @@ abstract class AbstractResponse extends ApiTestCase
|
||||
*
|
||||
* @throws ReflectionException
|
||||
* @dataProvider isSuccessfulDataProvider
|
||||
* @covers \D3\LinkmobilityClient\SMS\Response::isSuccessful
|
||||
*/
|
||||
public function testIsSuccessful($statusCode, $expected)
|
||||
{
|
||||
@ -180,6 +198,7 @@ abstract class AbstractResponse extends ApiTestCase
|
||||
*
|
||||
* @throws ReflectionException
|
||||
* @dataProvider getErrorMessageDataProvider
|
||||
* @covers \D3\LinkmobilityClient\SMS\Response::getErrorMessage
|
||||
*/
|
||||
public function testGetErrorMessage($successful, $expected)
|
||||
{
|
||||
|
@ -30,6 +30,7 @@ class RequestFactoryTest extends ApiTestCase
|
||||
* @test
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LinkmobilityClient\SMS\RequestFactory::__construct
|
||||
*/
|
||||
public function testConstruct()
|
||||
{
|
||||
@ -59,6 +60,7 @@ class RequestFactoryTest extends ApiTestCase
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @dataProvider getTextSmsRequestDataProvider
|
||||
* @covers \D3\LinkmobilityClient\SMS\RequestFactory::getSmsRequest
|
||||
*/
|
||||
public function testGetTextSmsRequest($encoding, $expectedClass)
|
||||
{
|
||||
@ -107,6 +109,7 @@ class RequestFactoryTest extends ApiTestCase
|
||||
* @test
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LinkmobilityClient\SMS\RequestFactory::getSmsLength
|
||||
*/
|
||||
public function testGetSmsLengthInstance()
|
||||
{
|
||||
|
@ -13,9 +13,10 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\LinkmobilityClient\Tests;
|
||||
namespace D3\LinkmobilityClient\Tests\Url;
|
||||
|
||||
use D3\LinkmobilityClient\Url;
|
||||
use D3\LinkmobilityClient\Tests\ApiTestCase;
|
||||
use D3\LinkmobilityClient\Url\Url;
|
||||
use ReflectionException;
|
||||
|
||||
class UrlTest extends ApiTestCase
|
||||
@ -44,6 +45,7 @@ class UrlTest extends ApiTestCase
|
||||
* @test
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LinkmobilityClient\Url\Url::getBaseUri
|
||||
*/
|
||||
public function testGetBaseUri()
|
||||
{
|
||||
@ -58,4 +60,36 @@ class UrlTest extends ApiTestCase
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LinkmobilityClient\Url\Url::getTextSmsUri
|
||||
*/
|
||||
public function testGetTextSmsUri()
|
||||
{
|
||||
$uri = $this->callMethod(
|
||||
$this->url,
|
||||
'getTextSmsUri'
|
||||
);
|
||||
|
||||
$this->assertIsString($uri);
|
||||
$this->assertStringStartsWith('/', $uri);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LinkmobilityClient\Url\Url::getBinarySmsUri
|
||||
*/
|
||||
public function testGetBinarySmsUri()
|
||||
{
|
||||
$uri = $this->callMethod(
|
||||
$this->url,
|
||||
'getBinarySmsUri'
|
||||
);
|
||||
|
||||
$this->assertIsString($uri);
|
||||
$this->assertStringStartsWith('/', $uri);
|
||||
}
|
||||
}
|
@ -16,10 +16,13 @@ declare(strict_types=1);
|
||||
namespace D3\LinkmobilityClient\Tests\ValueObject;
|
||||
|
||||
use Assert\InvalidArgumentException;
|
||||
use D3\LinkmobilityClient\Exceptions\RecipientException;
|
||||
use D3\LinkmobilityClient\Tests\ApiTestCase;
|
||||
use D3\LinkmobilityClient\ValueObject\Recipient;
|
||||
use libphonenumber\NumberParseException;
|
||||
use libphonenumber\PhoneNumber;
|
||||
use libphonenumber\PhoneNumberFormat;
|
||||
use libphonenumber\PhoneNumberType;
|
||||
use libphonenumber\PhoneNumberUtil;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use ReflectionException;
|
||||
@ -29,17 +32,22 @@ class RecipientTest extends ApiTestCase
|
||||
/** @var Recipient */
|
||||
public $recipient;
|
||||
|
||||
private $phoneNumberFixture = '01527565839';
|
||||
private $phoneNumberFixture;
|
||||
private $phoneCountryFixture = 'DE';
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws NumberParseException
|
||||
* @throws RecipientException
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
@ -57,17 +65,21 @@ class RecipientTest extends ApiTestCase
|
||||
* @test
|
||||
* @return void
|
||||
* @throws NumberParseException
|
||||
* @throws RecipientException
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LinkmobilityClient\ValueObject\Recipient::__construct
|
||||
*/
|
||||
public function testConstructValid()
|
||||
{
|
||||
/** @var PhoneNumberUtil|MockObject $phoneNumberUtilMock */
|
||||
$phoneNumberUtilMock = $this->getMockBuilder(PhoneNumberUtil::class)
|
||||
->onlyMethods(['parse', 'format'])
|
||||
->onlyMethods(['parse', 'format', 'isValidNumber', 'getNumberType'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$phoneNumberUtilMock->method('parse')->willReturn(new PhoneNumber());
|
||||
$phoneNumberUtilMock->method('format')->willReturn('+491527565839');
|
||||
$phoneNumberUtilMock->method('isValidNumber')->willReturn(true);
|
||||
$phoneNumberUtilMock->method('getNumberType')->willReturn(PhoneNumberType::MOBILE);
|
||||
|
||||
/** @var Recipient|MockObject $recipientMock */
|
||||
$recipientMock = $this->getMockBuilder(Recipient::class)
|
||||
@ -78,7 +90,7 @@ class RecipientTest extends ApiTestCase
|
||||
$recipientMock->__construct($this->phoneNumberFixture, $this->phoneCountryFixture);
|
||||
|
||||
$this->assertSame(
|
||||
'491527565839',
|
||||
'+491527565839',
|
||||
$this->callMethod(
|
||||
$recipientMock,
|
||||
'get'
|
||||
@ -100,17 +112,20 @@ class RecipientTest extends ApiTestCase
|
||||
* @param $number
|
||||
* @param $country
|
||||
* @param $validNumber
|
||||
* @param $numberType
|
||||
* @param $expectedException
|
||||
*
|
||||
* @return void
|
||||
* @throws NumberParseException
|
||||
* @throws RecipientException
|
||||
* @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 */
|
||||
$phoneNumberUtilMock = $this->getMockBuilder(PhoneNumberUtil::class)
|
||||
->onlyMethods(['parse', 'format', 'isValidNumber'])
|
||||
->onlyMethods(['parse', 'format', 'isValidNumber', 'getNumberType'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
if ($number === 'abc') {
|
||||
@ -120,6 +135,7 @@ class RecipientTest extends ApiTestCase
|
||||
}
|
||||
$phoneNumberUtilMock->method('format')->willReturn($number);
|
||||
$phoneNumberUtilMock->method('isValidNumber')->willReturn($validNumber);
|
||||
$phoneNumberUtilMock->method('getNumberType')->willReturn($numberType);
|
||||
|
||||
/** @var Recipient|MockObject $recipientMock */
|
||||
$recipientMock = $this->getMockBuilder(Recipient::class)
|
||||
@ -137,17 +153,23 @@ class RecipientTest extends ApiTestCase
|
||||
*/
|
||||
public function constructInvalidDataProvider(): array
|
||||
{
|
||||
$phoneUtil = PhoneNumberUtil::getInstance();
|
||||
$example = $phoneUtil->getExampleNumberForType($this->phoneCountryFixture, PhoneNumberType::MOBILE);
|
||||
$phoneNumberFixture = $phoneUtil->format($example, PhoneNumberFormat::NATIONAL);
|
||||
|
||||
return [
|
||||
'empty number' => ['', 'DE', true, InvalidArgumentException::class],
|
||||
'invalid country code' => [$this->phoneNumberFixture, 'DEX', true, InvalidArgumentException::class],
|
||||
'unparsable' => ['abc', 'DE', true, NumberParseException::class],
|
||||
'invalid number' => ['abc', 'DE', false, NumberParseException::class]
|
||||
'empty number' => ['', 'DE', true, PhoneNumberType::MOBILE, InvalidArgumentException::class],
|
||||
'invalid country code' => [$phoneNumberFixture, 'DEX', true, PhoneNumberType::MOBILE, InvalidArgumentException::class],
|
||||
'unparsable' => ['abc', 'DE', true, PhoneNumberType::MOBILE, NumberParseException::class],
|
||||
'invalid number' => ['abcd', 'DE', false, PhoneNumberType::MOBILE, RecipientException::class],
|
||||
'not mobile number' => ['abcd', 'DE', true, PhoneNumberType::FIXED_LINE, RecipientException::class]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LinkmobilityClient\ValueObject\Recipient::getPhoneNumberUtil
|
||||
*/
|
||||
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'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -16,11 +16,14 @@ declare(strict_types=1);
|
||||
namespace D3\LinkmobilityClient\Tests\ValueObject;
|
||||
|
||||
use Assert\InvalidArgumentException;
|
||||
use D3\LinkmobilityClient\Exceptions\NoSenderDefinedException;
|
||||
use D3\LinkmobilityClient\Exceptions\RecipientException;
|
||||
use D3\LinkmobilityClient\Tests\ApiTestCase;
|
||||
use D3\LinkmobilityClient\ValueObject\Sender;
|
||||
use libphonenumber\NumberParseException;
|
||||
use libphonenumber\PhoneNumber;
|
||||
use libphonenumber\PhoneNumberFormat;
|
||||
use libphonenumber\PhoneNumberType;
|
||||
use libphonenumber\PhoneNumberUtil;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use ReflectionException;
|
||||
@ -30,7 +33,7 @@ class SenderTest extends ApiTestCase
|
||||
/** @var Sender */
|
||||
public $sender;
|
||||
|
||||
private $phoneNumberFixture = '015792300219';
|
||||
private $phoneNumberFixture;
|
||||
private $phoneCountryFixture = 'DE';
|
||||
|
||||
/**
|
||||
@ -42,6 +45,11 @@ class SenderTest extends ApiTestCase
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
@ -61,8 +69,10 @@ class SenderTest extends ApiTestCase
|
||||
* @throws NumberParseException
|
||||
* @throws RecipientException
|
||||
* @throws ReflectionException
|
||||
* @dataProvider constructValidDataProvider
|
||||
* @covers \D3\LinkmobilityClient\ValueObject\Sender::__construct
|
||||
*/
|
||||
public function testConstructValid()
|
||||
public function testConstructValid($number, $country, $hasNumber)
|
||||
{
|
||||
/** @var PhoneNumberUtil|MockObject $phoneNumberUtilMock */
|
||||
$phoneNumberUtilMock = $this->getMockBuilder(PhoneNumberUtil::class)
|
||||
@ -79,17 +89,33 @@ class SenderTest extends ApiTestCase
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$senderMock->method('getPhoneNumberUtil')->willReturn($phoneNumberUtilMock);
|
||||
$senderMock->__construct($this->phoneNumberFixture, $this->phoneCountryFixture);
|
||||
$senderMock->__construct($number, $country);
|
||||
|
||||
$this->assertSame(
|
||||
'4915792300219',
|
||||
$hasNumber,
|
||||
$this->callMethod(
|
||||
$senderMock,
|
||||
'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
|
||||
* @param $number
|
||||
@ -100,6 +126,7 @@ class SenderTest extends ApiTestCase
|
||||
* @throws NumberParseException
|
||||
* @throws RecipientException
|
||||
* @dataProvider constructInvalidDataProvider
|
||||
* @covers \D3\LinkmobilityClient\ValueObject\Sender::__construct
|
||||
*/
|
||||
public function testConstructInvalid($number, $country, $validNumber, $expectedException)
|
||||
{
|
||||
@ -109,12 +136,14 @@ class SenderTest extends ApiTestCase
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
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 {
|
||||
$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('isValidNumber')->willReturn($validNumber);
|
||||
$phoneNumberUtilMock->method('isValidNumber')->willReturn((bool) $validNumber);
|
||||
|
||||
/** @var Sender|MockObject $senderMock */
|
||||
$senderMock = $this->getMockBuilder(Sender::class)
|
||||
@ -124,7 +153,12 @@ class SenderTest extends ApiTestCase
|
||||
$senderMock->method('getPhoneNumberUtil')->willReturn($phoneNumberUtilMock);
|
||||
|
||||
$this->expectException($expectedException);
|
||||
$senderMock->__construct($number, $country);
|
||||
|
||||
$this->callMethod(
|
||||
$senderMock,
|
||||
'__construct',
|
||||
[$number, $country]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -132,17 +166,22 @@ class SenderTest extends ApiTestCase
|
||||
*/
|
||||
public function constructInvalidDataProvider(): array
|
||||
{
|
||||
$phoneUtil = PhoneNumberUtil::getInstance();
|
||||
$example = $phoneUtil->getExampleNumberForType($this->phoneCountryFixture, PhoneNumberType::MOBILE);
|
||||
$phoneNumberFixture = $phoneUtil->format($example, PhoneNumberFormat::NATIONAL);
|
||||
|
||||
return [
|
||||
'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],
|
||||
'invalid number' => ['abc', 'DE', false, NumberParseException::class]
|
||||
'invalid number' => ['abcd', 'DE', false, RecipientException::class]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LinkmobilityClient\ValueObject\Sender::getPhoneNumberUtil
|
||||
*/
|
||||
public function testGetPhoneNumberUtil()
|
||||
{
|
||||
@ -154,4 +193,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
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsBinaryMessage::__construct
|
||||
*/
|
||||
public function testConstructValid()
|
||||
{
|
||||
@ -89,6 +90,7 @@ class SmsBinaryMessageTest extends ApiTestCase
|
||||
*
|
||||
* @throws ReflectionException
|
||||
* @dataProvider constructInvalidDataProvider
|
||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsBinaryMessage::__construct
|
||||
*/
|
||||
public function testConstructInvalid($binaryMessage, $valid, $expectedException)
|
||||
{
|
||||
@ -136,6 +138,7 @@ class SmsBinaryMessageTest extends ApiTestCase
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsBinaryMessage::getSmsLength
|
||||
*/
|
||||
public function testGetSmsLengthInstance()
|
||||
{
|
||||
@ -149,7 +152,9 @@ class SmsBinaryMessageTest extends ApiTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsBinaryMessage::chunkCount
|
||||
*/
|
||||
public function testGetChunkCount()
|
||||
{
|
||||
@ -180,7 +185,9 @@ class SmsBinaryMessageTest extends ApiTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsBinaryMessage::length
|
||||
*/
|
||||
public function testGetSize()
|
||||
{
|
||||
@ -211,7 +218,10 @@ class SmsBinaryMessageTest extends ApiTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsBinaryMessage::getMessageContent
|
||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsMessageAbstract::getMessageContent
|
||||
*/
|
||||
public function testGetMessageContent()
|
||||
{
|
||||
|
@ -42,6 +42,7 @@ class SmsTextMessageTest extends SmsBinaryMessageTest
|
||||
* @test
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsTextMessage::__construct
|
||||
*/
|
||||
public function testConstructValid()
|
||||
{
|
||||
@ -78,6 +79,7 @@ class SmsTextMessageTest extends SmsBinaryMessageTest
|
||||
*
|
||||
* @throws ReflectionException
|
||||
* @dataProvider constructInvalidDataProvider
|
||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsTextMessage::__construct
|
||||
*/
|
||||
public function testConstructInvalid($binaryMessage, $valid, $expectedException)
|
||||
{
|
||||
|
88
Tests/ValueObject/ValueObjectTest.php
Normal file
88
Tests/ValueObject/ValueObjectTest.php
Normal file
@ -0,0 +1,88 @@
|
||||
<?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\Exceptions\NoSenderDefinedException;
|
||||
use D3\LinkmobilityClient\Exceptions\RecipientException;
|
||||
use D3\LinkmobilityClient\Tests\ApiTestCase;
|
||||
use D3\LinkmobilityClient\ValueObject\Sender;
|
||||
use D3\LinkmobilityClient\ValueObject\ValueObject;
|
||||
use libphonenumber\NumberParseException;
|
||||
use libphonenumber\PhoneNumber;
|
||||
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',
|
||||
['']
|
||||
);
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "d3/linkmobility-php-client",
|
||||
"type": "library",
|
||||
"description": "PHP client for LINK Mobility Austria API",
|
||||
"description": "PHP client for LINK Mobility API",
|
||||
"keywords": [
|
||||
"LINK Mobility",
|
||||
"php",
|
||||
@ -21,11 +21,10 @@
|
||||
"GPL-3.0-or-later"
|
||||
],
|
||||
"require": {
|
||||
"php": "^7.0",
|
||||
"php": "^7.0 || ^8.0",
|
||||
"beberlei/assert": "^2.9.9",
|
||||
"guzzlehttp/guzzle": "~6.2",
|
||||
"guzzlehttp/guzzle": "~6.2 || ^7.4",
|
||||
"psr/http-message": "~1.0",
|
||||
"symfony/options-resolver": "^4.4.37",
|
||||
"phlib/sms-length": "^1.1.0 || ^2.0.0",
|
||||
"giggsey/libphonenumber-for-php": "^8.12.50",
|
||||
"ext-json": "*"
|
||||
|
@ -5,7 +5,7 @@
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true">
|
||||
|
||||
<testsuite name="tankerkoenig">
|
||||
<testsuite name="linkmobility">
|
||||
<directory>./Tests</directory>
|
||||
</testsuite>
|
||||
|
||||
|
@ -18,11 +18,12 @@ namespace D3\LinkmobilityClient;
|
||||
use D3\LinkmobilityClient\Exceptions\ApiException;
|
||||
use D3\LinkmobilityClient\Exceptions\ExceptionMessages;
|
||||
use D3\LinkmobilityClient\Request\RequestInterface;
|
||||
use D3\LinkmobilityClient\Url\Url;
|
||||
use D3\LinkmobilityClient\Url\UrlInterface;
|
||||
use GuzzleHttp\ClientInterface;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use InvalidArgumentException;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class Client
|
||||
{
|
||||
@ -30,8 +31,6 @@ class Client
|
||||
public $apiUrl;
|
||||
public $requestClient;
|
||||
|
||||
private $logger;
|
||||
|
||||
public function __construct(string $accessToken, UrlInterface $apiUrl = null, ClientInterface $client = null)
|
||||
{
|
||||
$this->accessToken = $accessToken;
|
||||
@ -69,9 +68,7 @@ class Client
|
||||
{
|
||||
$options['headers']['Authorization'] = 'Bearer '.$this->accessToken;
|
||||
|
||||
if ($this->hasLogger()) {
|
||||
$this->getLogger()->debug('request '.$url, $options);
|
||||
}
|
||||
$this->getLoggerHandler()->getLogger()->debug('linkmobility request: '.$url, $options);
|
||||
|
||||
$response = $this->requestClient->request(
|
||||
$method,
|
||||
@ -81,45 +78,22 @@ class Client
|
||||
|
||||
if ($response->getStatusCode() != 200) {
|
||||
$message = sprintf(ExceptionMessages::NOK_REQUEST_RETURN, $url, $response->getStatusCode());
|
||||
if ($this->hasLogger()) {
|
||||
$this->getLogger()->error($message);
|
||||
}
|
||||
$response->getBody()->rewind();
|
||||
$this->getLoggerHandler()->getLogger()->error($message, [$response->getBody()->getContents()]);
|
||||
throw new ApiException($message);
|
||||
}
|
||||
|
||||
if ($this->hasLogger()) {
|
||||
$response->getBody()->rewind();
|
||||
$this->getLogger()->debug('response', [$response->getBody()->getContents()]);
|
||||
}
|
||||
$response->getBody()->rewind();
|
||||
$this->getLoggerHandler()->getLogger()->debug('response', [$response->getBody()->getContents()]);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $logger
|
||||
*
|
||||
* @return Client
|
||||
* @return LoggerHandler
|
||||
*/
|
||||
public function setLogger(LoggerInterface $logger): Client
|
||||
public function getLoggerHandler(): LoggerHandler
|
||||
{
|
||||
$this->logger = $logger;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function hasLogger(): bool
|
||||
{
|
||||
return $this->logger instanceof LoggerInterface;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return LoggerInterface|null
|
||||
*/
|
||||
public function getLogger()
|
||||
{
|
||||
return $this->hasLogger() ? $this->logger : null;
|
||||
return LoggerHandler::getInstance();
|
||||
}
|
||||
}
|
||||
|
@ -17,11 +17,15 @@ namespace D3\LinkmobilityClient\Exceptions;
|
||||
|
||||
class ExceptionMessages
|
||||
{
|
||||
public const INVALID_SENDER = 'invalid sender phone number';
|
||||
public const INVALID_SENDER = 'invalid sender phone number';
|
||||
|
||||
public const NOK_REQUEST_RETURN = 'request %1$s returns status code %2$s';
|
||||
public const NOK_REQUEST_RETURN = 'request %1$s returns status code %2$s';
|
||||
|
||||
public const INVALID_RECIPIENT_PHONE = 'invalid recipient phone number';
|
||||
public const INVALID_RECIPIENT_PHONE = 'invalid recipient phone number';
|
||||
|
||||
public const NOT_A_MOBILE_NUMBER = 'not a mobile number';
|
||||
public const NOT_A_MOBILE_NUMBER = 'not a mobile number';
|
||||
|
||||
public const EMPTY_RECIPIENT_LIST = 'request must contain a valid recipient';
|
||||
|
||||
public const DEBUG_NOSENDERORCOUNTRYCODE= 'no sender number or sender country code defined, use fallback to account default';
|
||||
}
|
||||
|
20
src/Exceptions/NoSenderDefinedException.php
Normal file
20
src/Exceptions/NoSenderDefinedException.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?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\Exceptions;
|
||||
|
||||
class NoSenderDefinedException extends LinkmobilityException
|
||||
{
|
||||
}
|
59
src/LoggerHandler.php
Normal file
59
src/LoggerHandler.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?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;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Psr\Log\NullLogger;
|
||||
|
||||
class LoggerHandler
|
||||
{
|
||||
/** @var LoggerHandler */
|
||||
private static $instance = null;
|
||||
private $logger;
|
||||
|
||||
/**
|
||||
* @return LoggerHandler
|
||||
*/
|
||||
public static function getInstance(): LoggerHandler
|
||||
{
|
||||
if (self::$instance === null) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->setLogger(new NullLogger());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $logger
|
||||
*/
|
||||
public function setLogger(LoggerInterface $logger)
|
||||
{
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return LoggerInterface
|
||||
*/
|
||||
public function getLogger(): LoggerInterface
|
||||
{
|
||||
return $this->logger;
|
||||
}
|
||||
}
|
@ -16,13 +16,8 @@ declare(strict_types=1);
|
||||
namespace D3\LinkmobilityClient\RecipientsList;
|
||||
|
||||
use D3\LinkmobilityClient\Client;
|
||||
use D3\LinkmobilityClient\Exceptions\ExceptionMessages;
|
||||
use D3\LinkmobilityClient\Exceptions\RecipientException;
|
||||
use D3\LinkmobilityClient\ValueObject\Recipient;
|
||||
use Iterator;
|
||||
use libphonenumber\NumberParseException;
|
||||
use libphonenumber\PhoneNumberType;
|
||||
use libphonenumber\PhoneNumberUtil;
|
||||
|
||||
class RecipientsList implements RecipientsListInterface, Iterator
|
||||
{
|
||||
@ -41,14 +36,6 @@ class RecipientsList implements RecipientsListInterface, Iterator
|
||||
$this->setClient($client);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return PhoneNumberUtil
|
||||
*/
|
||||
protected function getPhoneNumberUtil(): PhoneNumberUtil
|
||||
{
|
||||
return PhoneNumberUtil::getInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Recipient $recipient
|
||||
*
|
||||
@ -56,34 +43,7 @@ class RecipientsList implements RecipientsListInterface, Iterator
|
||||
*/
|
||||
public function add(Recipient $recipient): RecipientsListInterface
|
||||
{
|
||||
$phoneUtil = $this->getPhoneNumberUtil();
|
||||
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) {
|
||||
if ($this->getClient()->hasLogger()) {
|
||||
$this->getClient()->getLogger()->info($e->getMessage());
|
||||
}
|
||||
} catch (RecipientException $e) {
|
||||
if ($this->getClient()->hasLogger()) {
|
||||
$this->getClient()->getLogger()->info($e->getMessage());
|
||||
}
|
||||
}
|
||||
$this->recipients[ md5(serialize($recipient)) ] = $recipient;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@ -98,12 +58,15 @@ class RecipientsList implements RecipientsListInterface, Iterator
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getRecipients(): array
|
||||
{
|
||||
return array_values(
|
||||
array_map(
|
||||
function (Recipient $recipient) {
|
||||
return $recipient->get();
|
||||
return $recipient->getFormatted();
|
||||
},
|
||||
$this->recipients
|
||||
)
|
||||
|
@ -17,6 +17,7 @@ namespace D3\LinkmobilityClient\Request;
|
||||
|
||||
use Assert\Assert;
|
||||
use D3\LinkmobilityClient\Client;
|
||||
use D3\LinkmobilityClient\Exceptions\ExceptionMessages;
|
||||
use D3\LinkmobilityClient\RecipientsList\RecipientsList;
|
||||
use D3\LinkmobilityClient\RecipientsList\RecipientsListInterface;
|
||||
use D3\LinkmobilityClient\Response\ResponseInterface;
|
||||
@ -122,6 +123,11 @@ abstract class Request implements RequestInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
abstract public function getUri(): string;
|
||||
|
||||
/**
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
@ -135,7 +141,7 @@ abstract class Request implements RequestInterface
|
||||
Assert::that($this->getOptions())->isArray();
|
||||
|
||||
Assert::that($this->getRecipientsList())->isInstanceOf(RecipientsList::class)->notEmpty();
|
||||
Assert::that($this->getRecipientsList()->getRecipients())->notEmpty('request must contain a valid recipient');
|
||||
Assert::that($this->getRecipientsList()->getRecipients())->notEmpty(ExceptionMessages::EMPTY_RECIPIENT_LIST);
|
||||
Assert::thatAll($this->getRecipientsList())->isInstanceOf(Recipient::class)->notEmpty();
|
||||
|
||||
// optional properties
|
||||
@ -460,7 +466,7 @@ abstract class Request implements RequestInterface
|
||||
*/
|
||||
public function getSenderAddressType()
|
||||
{
|
||||
return $this->senderAddressType;
|
||||
return $this->getSenderAddress() && $this->getSenderAddress()->get() ? $this->senderAddressType : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -16,6 +16,7 @@ declare(strict_types=1);
|
||||
namespace D3\LinkmobilityClient\Request;
|
||||
|
||||
use D3\LinkmobilityClient\Client;
|
||||
use D3\LinkmobilityClient\RecipientsList\RecipientsListInterface;
|
||||
use D3\LinkmobilityClient\ValueObject\SmsMessageInterface;
|
||||
use InvalidArgumentException;
|
||||
use Psr\Http\Message\ResponseInterface as PsrResponseInterface;
|
||||
@ -42,9 +43,18 @@ interface RequestInterface
|
||||
public const SENDERADDRESSTYPE_ALPHANUMERIC = 'alphanumeric';
|
||||
public const SENDERADDRESSTYPE_SHORTCODE = 'shortcode';
|
||||
|
||||
/**
|
||||
* @param SmsMessageInterface $message
|
||||
* @param Client $client
|
||||
*/
|
||||
public function __construct(SmsMessageInterface $message, Client $client);
|
||||
|
||||
public function setMethod(string $method);
|
||||
/**
|
||||
* @param string $method
|
||||
*
|
||||
* @return Request
|
||||
*/
|
||||
public function setMethod(string $method): Request;
|
||||
|
||||
/**
|
||||
* Must return the HTTP verb for this request, i.e. GET, POST, PUT
|
||||
@ -53,6 +63,18 @@ interface RequestInterface
|
||||
*/
|
||||
public function getMethod(): string;
|
||||
|
||||
/**
|
||||
* @param bool $test
|
||||
*
|
||||
* @return Request
|
||||
*/
|
||||
public function setTestMode(bool $test): Request;
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function getTestMode(): bool;
|
||||
|
||||
/**
|
||||
* Must return the URI for the request with a leading slash, i.e. /messages.json
|
||||
*
|
||||
@ -81,6 +103,11 @@ interface RequestInterface
|
||||
*/
|
||||
public function getResponseInstance(PsrResponseInterface $rawResponse): LMResponseInterface;
|
||||
|
||||
/**
|
||||
* @return RecipientsListInterface
|
||||
*/
|
||||
public function getRecipientsList(): RecipientsListInterface;
|
||||
|
||||
/**
|
||||
* Must return the options for this request. If there are none, return [] (empty array)
|
||||
*
|
||||
|
@ -17,6 +17,7 @@ namespace D3\LinkmobilityClient\SMS;
|
||||
|
||||
use Assert\Assert;
|
||||
use D3\LinkmobilityClient\Request\Request;
|
||||
use D3\LinkmobilityClient\Url\Url;
|
||||
use D3\LinkmobilityClient\ValueObject\SmsBinaryMessage;
|
||||
use InvalidArgumentException;
|
||||
|
||||
@ -27,7 +28,7 @@ class BinaryRequest extends Request implements SmsRequestInterface
|
||||
*/
|
||||
public function getUri(): string
|
||||
{
|
||||
return '/rest/smsmessaging/binary';
|
||||
return (new Url())->getBinarySmsUri();
|
||||
}
|
||||
|
||||
public function getRawBody(): array
|
||||
|
@ -17,6 +17,7 @@ namespace D3\LinkmobilityClient\SMS;
|
||||
|
||||
use Assert\Assert;
|
||||
use D3\LinkmobilityClient\Request\Request;
|
||||
use D3\LinkmobilityClient\Url\Url;
|
||||
use D3\LinkmobilityClient\ValueObject\SmsTextMessage;
|
||||
use InvalidArgumentException;
|
||||
|
||||
@ -27,7 +28,7 @@ class TextRequest extends Request implements SmsRequestInterface
|
||||
*/
|
||||
public function getUri(): string
|
||||
{
|
||||
return '/rest/smsmessaging/text';
|
||||
return (new Url())->getTextSmsUri();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -13,7 +13,7 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\LinkmobilityClient;
|
||||
namespace D3\LinkmobilityClient\Url;
|
||||
|
||||
class Url implements UrlInterface
|
||||
{
|
||||
@ -26,4 +26,20 @@ class Url implements UrlInterface
|
||||
{
|
||||
return $this->baseUri;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTextSmsUri()
|
||||
{
|
||||
return '/rest/smsmessaging/text';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getBinarySmsUri()
|
||||
{
|
||||
return '/rest/smsmessaging/binary';
|
||||
}
|
||||
}
|
@ -13,7 +13,7 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\LinkmobilityClient;
|
||||
namespace D3\LinkmobilityClient\Url;
|
||||
|
||||
interface UrlInterface
|
||||
{
|
@ -16,12 +16,23 @@ declare(strict_types=1);
|
||||
namespace D3\LinkmobilityClient\ValueObject;
|
||||
|
||||
use Assert\Assert;
|
||||
use D3\LinkmobilityClient\Exceptions\ExceptionMessages;
|
||||
use D3\LinkmobilityClient\Exceptions\RecipientException;
|
||||
use libphonenumber\NumberParseException;
|
||||
use libphonenumber\PhoneNumberFormat;
|
||||
use libphonenumber\PhoneNumberType;
|
||||
use libphonenumber\PhoneNumberUtil;
|
||||
|
||||
class Recipient extends StringValueObject
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $allowedNumberTypes = [
|
||||
PhoneNumberType::MOBILE,
|
||||
PhoneNumberType::FIXED_LINE_OR_MOBILE
|
||||
];
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
@ -32,15 +43,28 @@ class Recipient extends StringValueObject
|
||||
* @param string $iso2CountryCode
|
||||
*
|
||||
* @throws NumberParseException
|
||||
* @throws RecipientException
|
||||
*/
|
||||
public function __construct(string $number, string $iso2CountryCode)
|
||||
{
|
||||
Assert::that($number)->notEmpty();
|
||||
Assert::that($iso2CountryCode)->string()->length(2);
|
||||
|
||||
$phoneUtil = $this->getPhoneNumberUtil();
|
||||
|
||||
$phoneNumber = $phoneUtil->parse($number, strtoupper($iso2CountryCode));
|
||||
$number = ltrim($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);
|
||||
$this->countryCode = $iso2CountryCode;
|
||||
@ -61,4 +85,9 @@ class Recipient extends StringValueObject
|
||||
{
|
||||
return $this->countryCode;
|
||||
}
|
||||
|
||||
public function getFormatted()
|
||||
{
|
||||
return ltrim(parent::getFormatted(), '+');
|
||||
}
|
||||
}
|
||||
|
@ -17,12 +17,14 @@ namespace D3\LinkmobilityClient\ValueObject;
|
||||
|
||||
use Assert\Assert;
|
||||
use D3\LinkmobilityClient\Exceptions\ExceptionMessages;
|
||||
use D3\LinkmobilityClient\Exceptions\NoSenderDefinedException;
|
||||
use D3\LinkmobilityClient\Exceptions\RecipientException;
|
||||
use D3\LinkmobilityClient\LoggerHandler;
|
||||
use libphonenumber\NumberParseException;
|
||||
use libphonenumber\PhoneNumberFormat;
|
||||
use libphonenumber\PhoneNumberUtil;
|
||||
|
||||
class Sender extends StringValueObject
|
||||
class Sender extends ValueObject
|
||||
{
|
||||
/**
|
||||
* @param string $number
|
||||
@ -31,20 +33,30 @@ class Sender extends StringValueObject
|
||||
* @throws RecipientException
|
||||
* @throws NumberParseException
|
||||
*/
|
||||
public function __construct(string $number, string $iso2CountryCode)
|
||||
public function __construct(string $number = null, string $iso2CountryCode = null)
|
||||
{
|
||||
Assert::that($iso2CountryCode)->string()->length(2);
|
||||
try {
|
||||
if (is_null($number) || is_null($iso2CountryCode)) {
|
||||
throw new NoSenderDefinedException();
|
||||
}
|
||||
|
||||
$phoneUtil = $this->getPhoneNumberUtil();
|
||||
Assert::that($iso2CountryCode)->string()->length(2);
|
||||
|
||||
$phoneNumber = $phoneUtil->parse($number, strtoupper($iso2CountryCode));
|
||||
$number = ltrim($phoneUtil->format($phoneNumber, PhoneNumberFormat::E164), '+');
|
||||
$phoneUtil = $this->getPhoneNumberUtil();
|
||||
|
||||
if (false === $phoneUtil->isValidNumber($phoneNumber)) {
|
||||
throw new RecipientException(ExceptionMessages::INVALID_SENDER);
|
||||
$phoneNumber = $phoneUtil->parse($number, strtoupper($iso2CountryCode));
|
||||
$number = $phoneUtil->format($phoneNumber, PhoneNumberFormat::E164);
|
||||
|
||||
if (false === $phoneUtil->isValidNumber($phoneNumber)) {
|
||||
throw new RecipientException(ExceptionMessages::INVALID_SENDER);
|
||||
}
|
||||
|
||||
parent::__construct($number);
|
||||
} catch (NoSenderDefinedException $e) {
|
||||
LoggerHandler::getInstance()->getLogger()->debug(
|
||||
ExceptionMessages::DEBUG_NOSENDERORCOUNTRYCODE
|
||||
);
|
||||
}
|
||||
|
||||
parent::__construct($number);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -55,11 +67,8 @@ class Sender extends StringValueObject
|
||||
return PhoneNumberUtil::getInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getFormatted()
|
||||
{
|
||||
return parent::getFormatted();
|
||||
return ltrim(parent::getFormatted(), '+');
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ class SmsBinaryMessage extends SmsMessageAbstract
|
||||
public function getMessageContent()
|
||||
{
|
||||
return str_split(
|
||||
base64_encode($this->get()),
|
||||
base64_encode(parent::getMessageContent()),
|
||||
SmsLength::MAXIMUM_CHARACTERS_UCS2_SINGLE
|
||||
);
|
||||
}
|
||||
|
@ -19,13 +19,6 @@ use Assert\Assert;
|
||||
|
||||
abstract class StringValueObject extends ValueObject
|
||||
{
|
||||
public function __construct(string $number)
|
||||
{
|
||||
Assert::that($number)->notEmpty();
|
||||
|
||||
$this->value = $number;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return $this->get();
|
||||
@ -35,9 +28,4 @@ abstract class StringValueObject extends ValueObject
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
public function getFormatted()
|
||||
{
|
||||
return $this->get();
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,26 @@ declare(strict_types=1);
|
||||
|
||||
namespace D3\LinkmobilityClient\ValueObject;
|
||||
|
||||
use Assert\Assert;
|
||||
|
||||
abstract class ValueObject
|
||||
{
|
||||
protected $value;
|
||||
|
||||
public function __construct(string $number)
|
||||
{
|
||||
Assert::that($number)->notEmpty();
|
||||
|
||||
$this->value = $number;
|
||||
}
|
||||
|
||||
public function get()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
public function getFormatted()
|
||||
{
|
||||
return $this->get();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user