Compare commits
No commits in common. "main" and "1.0.0" have entirely different histories.
|
@ -6,7 +6,7 @@ $finder = PhpCsFixer\Finder::create()
|
||||||
|
|
||||||
$config = new PhpCsFixer\Config();
|
$config = new PhpCsFixer\Config();
|
||||||
return $config->setRules([
|
return $config->setRules([
|
||||||
'@PHP73Migration' => true,
|
'@PHP70Migration' => true,
|
||||||
'@PSR12' => true
|
'@PSR12' => true
|
||||||
])
|
])
|
||||||
->setFinder($finder)
|
->setFinder($finder)
|
||||||
|
|
93
CHANGELOG.md
93
CHANGELOG.md
|
@ -1,97 +1,10 @@
|
||||||
# Changelog
|
# 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).
|
|
||||||
|
|
||||||
## [Unreleased](https://git.d3data.de/D3Public/linkmobility-php-client/compare/2.2.0...rel_2.x)
|
## 1.0.0.0 (2022-07-13)
|
||||||
|
|
||||||
## [2.2.0](https://git.d3data.de/D3Public/linkmobility-php-client/compare/2.1.0...2.2.0) - 2023-06-29
|
|
||||||
### Added
|
|
||||||
- bump psr/http-message dependency to version 2
|
|
||||||
|
|
||||||
### Changed
|
|
||||||
- use assertion exception
|
|
||||||
|
|
||||||
## [2.1.0](https://git.d3data.de/D3Public/linkmobility-php-client/compare/2.0.3...2.1.0) - 2023-01-20
|
|
||||||
### Added
|
|
||||||
- installable in PHP > 8.0
|
|
||||||
- debug logger to log all comunications in debug mode (default Guzzle client only)
|
|
||||||
- retry middleware to request again in defined error cases (default Guzzle client only)
|
|
||||||
|
|
||||||
### Fixed
|
|
||||||
- missing getRecipientsList() in RecipientsListInterface
|
|
||||||
|
|
||||||
### Deprecated
|
|
||||||
- unused client argument in recipient list class
|
|
||||||
|
|
||||||
### Removed
|
|
||||||
- unused ApiException class
|
|
||||||
|
|
||||||
## [2.0.3](https://git.d3data.de/D3Public/linkmobility-php-client/compare/2.0.2...2.0.3) - 2022-12-26
|
|
||||||
### Changed
|
|
||||||
- allow Guzzle v7.3 for more backward compatibility
|
|
||||||
|
|
||||||
## [2.0.2](https://git.d3data.de/D3Public/linkmobility-php-client/compare/2.0.1...2.0.2) - 2022-07-28
|
|
||||||
### Changed
|
|
||||||
- add support note
|
|
||||||
- adjust readme
|
|
||||||
|
|
||||||
## [2.0.1](https://git.d3data.de/D3Public/linkmobility-php-client/compare/2.0.0...2.0.1) - 2022-07-28
|
|
||||||
### Added
|
|
||||||
- phpstan code checks
|
|
||||||
|
|
||||||
### Changed
|
|
||||||
- improve changelog
|
|
||||||
- improve code quality
|
|
||||||
|
|
||||||
### Fixed
|
|
||||||
- wrong return type of LoggerHandler::getInstance
|
|
||||||
|
|
||||||
## [2.0.0](https://git.d3data.de/D3Public/linkmobility-php-client/compare/1.3.0...2.0.0) - 2022-07-19
|
|
||||||
### Changed
|
|
||||||
- adjust to PHP >= 7.3 and current dependency packages
|
|
||||||
|
|
||||||
## [1.3.1](https://git.d3data.de/D3Public/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/D3Public/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/D3Public/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/D3Public/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/D3Public/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/D3Public/linkmobility-php-client/releases/tag/1.0.0) - 2022-07-13
|
|
||||||
### Added
|
|
||||||
- initial implementation
|
- initial implementation
|
||||||
- SMS requests (text or binary)
|
- SMS requests (text or binary)
|
||||||
- SMS responses
|
- SMS responses
|
||||||
- recipient managing
|
- recipient managing
|
12
README.en.md
12
README.en.md
|
@ -1,7 +1,7 @@
|
||||||
[![deutsche Version](https://logos.oxidmodule.com/de2_xs.svg)](README.md)
|
[![deutsche Version](https://logos.oxidmodule.com/de2_xs.svg)](README.md)
|
||||||
[![english version](https://logos.oxidmodule.com/en2_xs.svg)](README.en.md)
|
[![english version](https://logos.oxidmodule.com/en2_xs.svg)](README.en.md)
|
||||||
|
|
||||||
# LINK Mobility PHP API Client
|
# LINK Mobility Austria PHP API Client
|
||||||
|
|
||||||
[LINK Mobility](https://www.linkmobility.de/) provides a service for sending mobile messages (SMS, Whatsapp, RCS, Chatbot, ...).
|
[LINK Mobility](https://www.linkmobility.de/) provides a service for sending mobile messages (SMS, Whatsapp, RCS, Chatbot, ...).
|
||||||
|
|
||||||
|
@ -18,8 +18,8 @@ composer require d3/linkmobility-php-client
|
||||||
```
|
```
|
||||||
|
|
||||||
```
|
```
|
||||||
$client = new \D3\LinkmobilityClient\Client('personal accesstoken');
|
$client = new Client('personal accesstoken');
|
||||||
\D3\LinkmobilityClient\LoggerHandler::getInstance()->setLogger($logger); // optional
|
$client->setLogger($logger); // optional
|
||||||
$request = new D3\LinkmobilityClient\SMS\RequestFactory($message, $client)->getSmsRequest())
|
$request = new D3\LinkmobilityClient\SMS\RequestFactory($message, $client)->getSmsRequest())
|
||||||
->addRecipient(new D3\LinkmobilityClient\ValueObject\Recipient('recipient number', 'DE'));
|
->addRecipient(new D3\LinkmobilityClient\ValueObject\Recipient('recipient number', 'DE'));
|
||||||
$response = $client->request($request)
|
$response = $client->request($request)
|
||||||
|
@ -39,12 +39,6 @@ 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)
|
- Push to the Branch (git push origin feature/AmazingFeature)
|
||||||
- Open a Pull Request
|
- 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
|
## License
|
||||||
(status: 2022-07-13)
|
(status: 2022-07-13)
|
||||||
|
|
||||||
|
|
12
README.md
12
README.md
|
@ -1,7 +1,7 @@
|
||||||
[![deutsche Version](https://logos.oxidmodule.com/de2_xs.svg)](README.md)
|
[![deutsche Version](https://logos.oxidmodule.com/de2_xs.svg)](README.md)
|
||||||
[![english version](https://logos.oxidmodule.com/en2_xs.svg)](README.en.md)
|
[![english version](https://logos.oxidmodule.com/en2_xs.svg)](README.en.md)
|
||||||
|
|
||||||
# LINK Mobility PHP API Client
|
# LINK Mobility Austria PHP API Client
|
||||||
|
|
||||||
[LINK Mobility](https://www.linkmobility.de/) stellt einen Service zum Versenden von mobilen Nachrichten (SMS, Whatsapp, RCS, Chatbot, ...) zur VerfĂĽgung.
|
[LINK Mobility](https://www.linkmobility.de/) stellt einen Service zum Versenden von mobilen Nachrichten (SMS, Whatsapp, RCS, Chatbot, ...) zur VerfĂĽgung.
|
||||||
|
|
||||||
|
@ -18,8 +18,8 @@ composer require d3/linkmobility-php-client
|
||||||
```
|
```
|
||||||
|
|
||||||
```
|
```
|
||||||
$client = new \D3\LinkmobilityClient\Client('personal accesstoken');
|
$client = new Client('personal accesstoken');
|
||||||
\D3\LinkmobilityClient\LoggerHandler::getInstance()->setLogger($logger); // optional
|
$client->setLogger($logger); // optional
|
||||||
$request = new D3\LinkmobilityClient\SMS\RequestFactory($message, $client)->getSmsRequest())
|
$request = new D3\LinkmobilityClient\SMS\RequestFactory($message, $client)->getSmsRequest())
|
||||||
->addRecipient(new D3\LinkmobilityClient\ValueObject\Recipient('recipient number', 'DE'));
|
->addRecipient(new D3\LinkmobilityClient\ValueObject\Recipient('recipient number', 'DE'));
|
||||||
$response = $client->request($request)
|
$response = $client->request($request)
|
||||||
|
@ -39,12 +39,6 @@ Wenn Sie eine Verbesserungsvorschlag haben, legen Sie einen Fork des Respoitorie
|
||||||
- Ăśbertragen Sie den Branch (git push origin feature/AmazingFeature)
|
- Ăśbertragen Sie den Branch (git push origin feature/AmazingFeature)
|
||||||
- Ă–ffnen Sie einen Pull Request
|
- Ă–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
|
## Lizenz
|
||||||
(Stand: 13.07.2022)
|
(Stand: 13.07.2022)
|
||||||
|
|
||||||
|
|
|
@ -1,104 +0,0 @@
|
||||||
<?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')
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -31,7 +31,7 @@ abstract class ApiTestCase extends TestCase
|
||||||
* @return mixed
|
* @return mixed
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
*/
|
*/
|
||||||
public function callMethod($object, string $methodName, array $arguments = [])
|
public function callMethod(object $object, string $methodName, array $arguments = [])
|
||||||
{
|
{
|
||||||
$class = new ReflectionClass($object);
|
$class = new ReflectionClass($object);
|
||||||
$method = $class->getMethod($methodName);
|
$method = $class->getMethod($methodName);
|
||||||
|
@ -47,7 +47,7 @@ abstract class ApiTestCase extends TestCase
|
||||||
* @param $value
|
* @param $value
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
*/
|
*/
|
||||||
public function setValue($object, string $valueName, $value)
|
public function setValue(object $object, string $valueName, $value)
|
||||||
{
|
{
|
||||||
$reflection = new ReflectionClass($object);
|
$reflection = new ReflectionClass($object);
|
||||||
$property = $reflection->getProperty($valueName);
|
$property = $reflection->getProperty($valueName);
|
||||||
|
@ -63,7 +63,7 @@ abstract class ApiTestCase extends TestCase
|
||||||
* @return mixed
|
* @return mixed
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
*/
|
*/
|
||||||
public function getValue($object, string $valueName)
|
public function getValue(object $object, string $valueName)
|
||||||
{
|
{
|
||||||
$reflection = new ReflectionClass($object);
|
$reflection = new ReflectionClass($object);
|
||||||
$property = $reflection->getProperty($valueName);
|
$property = $reflection->getProperty($valueName);
|
||||||
|
|
|
@ -17,18 +17,20 @@ namespace D3\LinkmobilityClient\Tests;
|
||||||
|
|
||||||
use Assert\InvalidArgumentException;
|
use Assert\InvalidArgumentException;
|
||||||
use D3\LinkmobilityClient\Client;
|
use D3\LinkmobilityClient\Client;
|
||||||
use D3\LinkmobilityClient\LoggerHandler;
|
use D3\LinkmobilityClient\Exceptions\ApiException;
|
||||||
use D3\LinkmobilityClient\Request\RequestInterface;
|
use D3\LinkmobilityClient\Request\RequestInterface;
|
||||||
use D3\LinkmobilityClient\Response\Response;
|
use D3\LinkmobilityClient\Response\Response;
|
||||||
use D3\LinkmobilityClient\Response\ResponseInterface;
|
use D3\LinkmobilityClient\Response\ResponseInterface;
|
||||||
use D3\LinkmobilityClient\SMS\TextRequest;
|
use D3\LinkmobilityClient\SMS\TextRequest;
|
||||||
use D3\LinkmobilityClient\Url\Url;
|
use D3\LinkmobilityClient\Url;
|
||||||
use D3\LinkmobilityClient\Url\UrlInterface;
|
use D3\LinkmobilityClient\UrlInterface;
|
||||||
use GuzzleHttp\Client as GuzzleClient;
|
use GuzzleHttp\Client as GuzzleClient;
|
||||||
use GuzzleHttp\ClientInterface;
|
use GuzzleHttp\ClientInterface;
|
||||||
use GuzzleHttp\Psr7\Response as GuzzleResponse;
|
|
||||||
use PHPUnit\Framework\MockObject\MockObject;
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
|
use Psr\Http\Message\ResponseInterface as MessageResponseInterface;
|
||||||
use Psr\Http\Message\StreamInterface;
|
use Psr\Http\Message\StreamInterface;
|
||||||
|
use Psr\Log\AbstractLogger;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
use ReflectionException;
|
use ReflectionException;
|
||||||
|
|
||||||
class ClientTest extends ApiTestCase
|
class ClientTest extends ApiTestCase
|
||||||
|
@ -65,7 +67,6 @@ 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)
|
||||||
{
|
{
|
||||||
|
@ -93,38 +94,15 @@ 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()]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @test
|
|
||||||
* @throws ReflectionException
|
|
||||||
* @return void
|
|
||||||
* @covers \D3\LinkmobilityClient\Client::getDefaultClient
|
|
||||||
*/
|
|
||||||
public function testGetDefaultClient()
|
|
||||||
{
|
|
||||||
/** @var Client|MockObject $sut */
|
|
||||||
$sut = $this->getMockBuilder(Client::class)
|
|
||||||
->setConstructorArgs(['accessTokenFixture'])
|
|
||||||
->getMock();
|
|
||||||
|
|
||||||
$this->assertInstanceOf(
|
|
||||||
GuzzleClient::class,
|
|
||||||
$this->callMethod(
|
|
||||||
$sut,
|
|
||||||
'getDefaultClient'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @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)
|
||||||
|
@ -186,27 +164,48 @@ class ClientTest extends ApiTestCase
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'request is valid' => [true],
|
'request is valid' => [true],
|
||||||
'request is not valid' => [false],
|
'request is not valid' => [false]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
|
* @param $useLogger
|
||||||
|
* @param $okStatus
|
||||||
* @return void
|
* @return void
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
* @covers \D3\LinkmobilityClient\Client::rawRequest
|
* @dataProvider rawRequestDataProvider
|
||||||
*/
|
*/
|
||||||
public function testRawRequest()
|
public function testRawRequest($useLogger, $okStatus)
|
||||||
{
|
{
|
||||||
|
$statusCode = $okStatus ? '200' : '301';
|
||||||
|
|
||||||
/** @var StreamInterface|MockObject $streamMock */
|
/** @var StreamInterface|MockObject $streamMock */
|
||||||
$streamMock = $this->getMockBuilder(StreamInterface::class)
|
$streamMock = $this->getMockBuilder(StreamInterface::class)
|
||||||
->getMock();
|
->getMock();
|
||||||
|
|
||||||
/** @var GuzzleResponse|MockObject $responseMock */
|
/** @var MessageResponseInterface|MockObject $responseMock */
|
||||||
$responseMock = $this->getMockBuilder( GuzzleResponse::class)
|
$responseMock = $this->getMockBuilder(MessageResponseInterface::class)
|
||||||
|
->onlyMethods([
|
||||||
|
'getStatusCode',
|
||||||
|
'getBody',
|
||||||
|
'withStatus',
|
||||||
|
'getReasonPhrase',
|
||||||
|
'getProtocolVersion',
|
||||||
|
'withProtocolVersion',
|
||||||
|
'getHeaders',
|
||||||
|
'hasHeader',
|
||||||
|
'getHeader',
|
||||||
|
'getHeaderLine',
|
||||||
|
'withHeader',
|
||||||
|
'withAddedHeader',
|
||||||
|
'withoutHeader',
|
||||||
|
'withBody'
|
||||||
|
])
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock();
|
||||||
$responseMock->expects($this->atLeastOnce())
|
$responseMock->expects($this->atLeastOnce())->method('getStatusCode')->willReturn($statusCode);
|
||||||
|
$responseMock->expects($useLogger && $okStatus ? $this->atLeastOnce() : $this->never())
|
||||||
->method('getBody')->willReturn($streamMock);
|
->method('getBody')->willReturn($streamMock);
|
||||||
|
|
||||||
/** @var GuzzleClient|MockObject $requestClientMock */
|
/** @var GuzzleClient|MockObject $requestClientMock */
|
||||||
|
@ -215,69 +214,70 @@ class ClientTest extends ApiTestCase
|
||||||
->getMock();
|
->getMock();
|
||||||
$requestClientMock->expects($this->once())->method('request')->willReturn($responseMock);
|
$requestClientMock->expects($this->once())->method('request')->willReturn($responseMock);
|
||||||
|
|
||||||
|
/** @var LoggerInterface|MockObject $loggerMock */
|
||||||
|
$loggerMock = $this->getMockBuilder(AbstractLogger::class)
|
||||||
|
->onlyMethods(['debug', 'error', 'log'])
|
||||||
|
->getMock();
|
||||||
|
|
||||||
/** @var Client|MockObject $clientMock */
|
/** @var Client|MockObject $clientMock */
|
||||||
$clientMock = $this->getMockBuilder(Client::class)
|
$clientMock = $this->getMockBuilder(Client::class)
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->onlyMethods([
|
->onlyMethods([
|
||||||
'getLoggerHandler',
|
'hasLogger',
|
||||||
|
'getLogger'
|
||||||
])
|
])
|
||||||
->getMock();
|
->getMock();
|
||||||
|
$clientMock->method('hasLogger')->willReturn($useLogger);
|
||||||
|
$clientMock->expects($useLogger ? $this->atLeastOnce() : $this->never())
|
||||||
|
->method('getLogger')->willReturn($loggerMock);
|
||||||
$this->setValue($clientMock, 'requestClient', $requestClientMock);
|
$this->setValue($clientMock, 'requestClient', $requestClientMock);
|
||||||
|
|
||||||
|
if (false === $okStatus) {
|
||||||
|
$this->expectException(ApiException::class);
|
||||||
|
}
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
$responseMock,
|
$responseMock,
|
||||||
$this->callMethod($clientMock, 'rawRequest', ['myUrl'])
|
$this->callMethod($clientMock, 'rawRequest', ['myUrl'])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
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],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @return void
|
* @return void
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
* @covers \D3\LinkmobilityClient\Client::getLoggerHandler
|
|
||||||
*/
|
*/
|
||||||
public function testGetLoggerHandler()
|
public function testLogger()
|
||||||
{
|
{
|
||||||
$this->assertInstanceOf(
|
$this->assertFalse($this->callMethod($this->api, 'hasLogger'));
|
||||||
LoggerHandler::class,
|
$this->assertNull($this->callMethod($this->api, 'getLogger'));
|
||||||
$this->callMethod(
|
|
||||||
$this->api,
|
|
||||||
'getLoggerHandler'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/** @var LoggerInterface|MockObject $loggerMock */
|
||||||
* @test
|
$loggerMock = $this->getMockBuilder(AbstractLogger::class)
|
||||||
* @return void
|
->onlyMethods(['debug', 'error', 'log'])
|
||||||
* @throws \PHPUnit\Framework\ExpectationFailedException
|
->getMock();
|
||||||
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
|
|
||||||
* @covers \D3\LinkmobilityClient\Client::getLoggerMiddleware
|
|
||||||
*/
|
|
||||||
public function testGetLoggerMiddleware()
|
|
||||||
{
|
|
||||||
$this->assertIsCallable(
|
|
||||||
$this->callMethod(
|
|
||||||
$this->api,
|
|
||||||
'getLoggerMiddleware'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
$this->assertSame(
|
||||||
* @test
|
$this->api,
|
||||||
* @return void
|
$this->callMethod($this->api, 'setLogger', [$loggerMock])
|
||||||
* @throws \PHPUnit\Framework\ExpectationFailedException
|
);
|
||||||
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
|
|
||||||
* @covers \D3\LinkmobilityClient\Client::getRetryMiddleware
|
$this->assertTrue($this->callMethod($this->api, 'hasLogger'));
|
||||||
*/
|
$this->assertSame(
|
||||||
public function testGetRetryMiddleware()
|
$loggerMock,
|
||||||
{
|
$this->callMethod($this->api, 'getLogger')
|
||||||
$this->assertIsCallable(
|
|
||||||
$this->callMethod(
|
|
||||||
$this->api,
|
|
||||||
'getRetryMiddleware'
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,5 +7,5 @@ composer create-project -s dev --prefer-source [--repository '{"type": "vcs", "u
|
||||||
# Run tests
|
# Run tests
|
||||||
|
|
||||||
```
|
```
|
||||||
./vendor/bin/phpunit [--no-coverage] [--coverage-html=cov]
|
./vendor/bin/phpunit [--no-coverage]
|
||||||
```
|
```
|
||||||
|
|
|
@ -19,10 +19,13 @@ use D3\LinkmobilityClient\Client;
|
||||||
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\PhoneNumberFormat;
|
use libphonenumber\NumberParseException;
|
||||||
|
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;
|
||||||
|
|
||||||
|
@ -31,7 +34,7 @@ class RecipientsListTest extends ApiTestCase
|
||||||
/** @var RecipientsList */
|
/** @var RecipientsList */
|
||||||
public $recipientsList;
|
public $recipientsList;
|
||||||
|
|
||||||
private $phoneNumberFixture;
|
private $phoneNumberFixture = '01527565839';
|
||||||
private $phoneCountryFixture = 'DE';
|
private $phoneCountryFixture = 'DE';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -47,10 +50,6 @@ 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,7 +65,6 @@ class RecipientsListTest extends ApiTestCase
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @return void
|
* @return void
|
||||||
* @covers \D3\LinkmobilityClient\RecipientsList\RecipientsList::__construct
|
|
||||||
*/
|
*/
|
||||||
public function testConstruct()
|
public function testConstruct()
|
||||||
{
|
{
|
||||||
|
@ -86,10 +84,33 @@ 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'])
|
||||||
|
@ -98,6 +119,15 @@ 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')
|
||||||
|
@ -121,8 +151,90 @@ class RecipientsListTest extends ApiTestCase
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
* @covers \D3\LinkmobilityClient\RecipientsList\RecipientsList::clearRecipents
|
* @dataProvider addInvalidNumberDataProvider
|
||||||
* @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 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
|
||||||
*/
|
*/
|
||||||
public function testClearRecipents()
|
public function testClearRecipents()
|
||||||
{
|
{
|
||||||
|
@ -150,7 +262,6 @@ class RecipientsListTest extends ApiTestCase
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
* @covers \D3\LinkmobilityClient\RecipientsList\RecipientsList::getRecipients
|
|
||||||
*/
|
*/
|
||||||
public function testGetRecipients()
|
public function testGetRecipients()
|
||||||
{
|
{
|
||||||
|
@ -167,7 +278,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,
|
||||||
|
@ -179,7 +290,6 @@ class RecipientsListTest extends ApiTestCase
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
* @covers \D3\LinkmobilityClient\RecipientsList\RecipientsList::getRecipientsList
|
|
||||||
*/
|
*/
|
||||||
public function testGetRecipientsList()
|
public function testGetRecipientsList()
|
||||||
{
|
{
|
||||||
|
@ -211,10 +321,6 @@ 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()
|
||||||
{
|
{
|
||||||
|
@ -263,7 +369,6 @@ class RecipientsListTest extends ApiTestCase
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
* @covers \D3\LinkmobilityClient\RecipientsList\RecipientsList::valid
|
|
||||||
*/
|
*/
|
||||||
public function testValid()
|
public function testValid()
|
||||||
{
|
{
|
||||||
|
@ -280,7 +385,7 @@ class RecipientsListTest extends ApiTestCase
|
||||||
$this->recipientsList,
|
$this->recipientsList,
|
||||||
'recipients',
|
'recipients',
|
||||||
[
|
[
|
||||||
'fixture' => new stdClass(),
|
'fixture' => new stdClass()
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -295,15 +400,13 @@ 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,
|
||||||
|
@ -333,11 +436,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);
|
||||||
|
@ -347,11 +450,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);
|
||||||
|
@ -359,7 +462,7 @@ class RecipientsListTest extends ApiTestCase
|
||||||
|
|
||||||
$list = [
|
$list = [
|
||||||
'fixture' => $recipientMock,
|
'fixture' => $recipientMock,
|
||||||
'fixture2' => $recipientMock2,
|
'fixture2' => $recipientMock2
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->setValue(
|
$this->setValue(
|
||||||
|
|
|
@ -17,7 +17,6 @@ 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;
|
||||||
|
@ -25,10 +24,6 @@ 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;
|
||||||
|
@ -67,8 +62,6 @@ 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()
|
||||||
{
|
{
|
||||||
|
@ -89,46 +82,23 @@ abstract class AbstractRequest extends ApiTestCase
|
||||||
$requestMock->expects($this->atLeastOnce())->method('setMessage')->with($this->equalTo($messageMock))->willReturnSelf();
|
$requestMock->expects($this->atLeastOnce())->method('setMessage')->with($this->equalTo($messageMock))->willReturnSelf();
|
||||||
$requestMock->expects($this->atLeastOnce())->method('setClient')->with($this->equalTo($clientMock))->willReturnSelf();
|
$requestMock->expects($this->atLeastOnce())->method('setClient')->with($this->equalTo($clientMock))->willReturnSelf();
|
||||||
|
|
||||||
$this->callMethod(
|
$this->assertInstanceOf(
|
||||||
$requestMock,
|
Request::class,
|
||||||
'__construct',
|
|
||||||
[$messageMock, $clientMock]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @test
|
|
||||||
* @throws ReflectionException
|
|
||||||
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::getUri
|
|
||||||
* @covers \D3\LinkmobilityClient\SMS\TextRequest::getUri
|
|
||||||
*/
|
|
||||||
public function testGetUri()
|
|
||||||
{
|
|
||||||
$this->assertIsString(
|
|
||||||
$this->callMethod(
|
$this->callMethod(
|
||||||
$this->request,
|
$requestMock,
|
||||||
'getUri'
|
'__construct',
|
||||||
|
[$messageMock, $clientMock]
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @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()
|
||||||
{
|
{
|
||||||
$phoneUtil = PhoneNumberUtil::getInstance();
|
$recipient = new Recipient('015792300219', 'DE');
|
||||||
$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)
|
||||||
|
@ -151,20 +121,11 @@ 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()
|
||||||
{
|
{
|
||||||
$phoneUtil = PhoneNumberUtil::getInstance();
|
$recipient = new Recipient('015792300219', 'DE');
|
||||||
$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)
|
||||||
|
@ -190,9 +151,6 @@ 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()
|
||||||
{
|
{
|
||||||
|
@ -217,8 +175,6 @@ 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)
|
||||||
{
|
{
|
||||||
|
@ -258,25 +214,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()
|
||||||
{
|
{
|
||||||
|
@ -289,20 +245,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'
|
||||||
|
@ -336,10 +292,6 @@ 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()
|
||||||
{
|
{
|
||||||
|
@ -353,10 +305,6 @@ 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()
|
||||||
{
|
{
|
||||||
|
@ -366,8 +314,6 @@ 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()
|
||||||
{
|
{
|
||||||
|
@ -383,10 +329,6 @@ 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()
|
||||||
{
|
{
|
||||||
|
@ -396,10 +338,6 @@ 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()
|
||||||
{
|
{
|
||||||
|
@ -409,10 +347,6 @@ 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()
|
||||||
{
|
{
|
||||||
|
@ -422,8 +356,6 @@ 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()
|
||||||
{
|
{
|
||||||
|
@ -439,10 +371,6 @@ 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()
|
||||||
{
|
{
|
||||||
|
@ -452,10 +380,6 @@ 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()
|
||||||
{
|
{
|
||||||
|
@ -465,10 +389,6 @@ 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()
|
||||||
{
|
{
|
||||||
|
@ -478,10 +398,6 @@ 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()
|
||||||
{
|
{
|
||||||
|
@ -491,10 +407,6 @@ 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()
|
||||||
{
|
{
|
||||||
|
@ -504,8 +416,6 @@ 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()
|
||||||
{
|
{
|
||||||
|
@ -521,10 +431,6 @@ 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()
|
||||||
{
|
{
|
||||||
|
@ -534,10 +440,6 @@ 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()
|
||||||
{
|
{
|
||||||
|
@ -551,66 +453,15 @@ abstract class AbstractRequest extends ApiTestCase
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
* @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 testSetGetSenderAddressType($hasSender, $addressType, $expected)
|
public function setGetSenderAddressTypeTest()
|
||||||
{
|
{
|
||||||
/** @var Request|MockObject $request */
|
$this->checkGetterSetter('fixture', 'setSenderAddressType', 'getSenderAddressType');
|
||||||
$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
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::getSenderAddressTypes
|
|
||||||
* @covers \D3\LinkmobilityClient\SMS\TextRequest::getSenderAddressTypes
|
|
||||||
*/
|
*/
|
||||||
public function getSenderAddressTypesTest()
|
public function getSenderAddressTypesTest()
|
||||||
{
|
{
|
||||||
|
@ -626,10 +477,6 @@ 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()
|
||||||
{
|
{
|
||||||
|
@ -640,8 +487,6 @@ 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)
|
||||||
{
|
{
|
||||||
|
@ -676,7 +521,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('{}');
|
||||||
|
|
||||||
|
@ -685,22 +530,18 @@ 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()
|
||||||
{
|
{
|
||||||
|
@ -711,33 +552,4 @@ 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,16 +29,13 @@ 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(
|
||||||
'{
|
'{
|
||||||
|
@ -53,7 +50,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);
|
||||||
|
|
||||||
|
@ -86,7 +83,7 @@ abstract class AbstractResponse extends ApiTestCase
|
||||||
*/
|
*/
|
||||||
protected function checkProperties($expected, $propertyName, $methodName)
|
protected function checkProperties($expected, $propertyName, $methodName)
|
||||||
{
|
{
|
||||||
/** @var Response|MockObject $responseMock */
|
/** @var Response $response */
|
||||||
$responseMock = $this->getMockBuilder($this->testClassName)
|
$responseMock = $this->getMockBuilder($this->testClassName)
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->onlyMethods(['getContent'])
|
->onlyMethods(['getContent'])
|
||||||
|
@ -105,7 +102,6 @@ abstract class AbstractResponse extends ApiTestCase
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
* @covers \D3\LinkmobilityClient\SMS\Response::getInternalStatus
|
|
||||||
*/
|
*/
|
||||||
public function testGetInternalStatus()
|
public function testGetInternalStatus()
|
||||||
{
|
{
|
||||||
|
@ -115,7 +111,6 @@ abstract class AbstractResponse extends ApiTestCase
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
* @covers \D3\LinkmobilityClient\SMS\Response::getStatusMessage
|
|
||||||
*/
|
*/
|
||||||
public function testGetStatusMessage()
|
public function testGetStatusMessage()
|
||||||
{
|
{
|
||||||
|
@ -125,17 +120,6 @@ 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()
|
||||||
{
|
{
|
||||||
|
@ -145,7 +129,6 @@ abstract class AbstractResponse extends ApiTestCase
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
* @covers \D3\LinkmobilityClient\SMS\Response::getSmsCount
|
|
||||||
*/
|
*/
|
||||||
public function testGetSmsCount()
|
public function testGetSmsCount()
|
||||||
{
|
{
|
||||||
|
@ -159,7 +142,6 @@ 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)
|
||||||
{
|
{
|
||||||
|
@ -198,7 +180,6 @@ 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)
|
||||||
{
|
{
|
||||||
|
@ -226,7 +207,7 @@ abstract class AbstractResponse extends ApiTestCase
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'successful' => [true, ''],
|
'successful' => [true, ''],
|
||||||
'not successful'=> [false, 'fixtureMessage'],
|
'not successful'=> [false, 'fixtureMessage']
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,6 @@ 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()
|
||||||
{
|
{
|
||||||
|
@ -60,7 +59,6 @@ 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)
|
||||||
{
|
{
|
||||||
|
@ -100,8 +98,8 @@ class RequestFactoryTest extends ApiTestCase
|
||||||
public function getTextSmsRequestDataProvider(): array
|
public function getTextSmsRequestDataProvider(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'binary' => [SmsLength::ENCODING_UCS2, BinaryRequest::class],
|
'binary' => [RequestFactory::GSM_UCS2, BinaryRequest::class],
|
||||||
'ascii' => [SmsLength::ENCODING_7BIT, TextRequest::class],
|
'ascii' => [RequestFactory::GSM_7BIT, TextRequest::class]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,7 +107,6 @@ 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()
|
||||||
{
|
{
|
||||||
|
|
|
@ -13,10 +13,9 @@
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace D3\LinkmobilityClient\Tests\Url;
|
namespace D3\LinkmobilityClient\Tests;
|
||||||
|
|
||||||
use D3\LinkmobilityClient\Tests\ApiTestCase;
|
use D3\LinkmobilityClient\Url;
|
||||||
use D3\LinkmobilityClient\Url\Url;
|
|
||||||
use ReflectionException;
|
use ReflectionException;
|
||||||
|
|
||||||
class UrlTest extends ApiTestCase
|
class UrlTest extends ApiTestCase
|
||||||
|
@ -45,7 +44,6 @@ 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()
|
||||||
{
|
{
|
||||||
|
@ -60,36 +58,4 @@ 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,13 +16,10 @@ 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;
|
||||||
|
@ -32,22 +29,17 @@ class RecipientTest extends ApiTestCase
|
||||||
/** @var Recipient */
|
/** @var Recipient */
|
||||||
public $recipient;
|
public $recipient;
|
||||||
|
|
||||||
private $phoneNumberFixture;
|
private $phoneNumberFixture = '01527565839';
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,21 +57,17 @@ 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', 'isValidNumber', 'getNumberType'])
|
->onlyMethods(['parse', 'format'])
|
||||||
->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)
|
||||||
|
@ -90,7 +78,7 @@ class RecipientTest extends ApiTestCase
|
||||||
$recipientMock->__construct($this->phoneNumberFixture, $this->phoneCountryFixture);
|
$recipientMock->__construct($this->phoneNumberFixture, $this->phoneCountryFixture);
|
||||||
|
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
'+491527565839',
|
'491527565839',
|
||||||
$this->callMethod(
|
$this->callMethod(
|
||||||
$recipientMock,
|
$recipientMock,
|
||||||
'get'
|
'get'
|
||||||
|
@ -112,20 +100,17 @@ 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, $numberType, $expectedException)
|
public function testConstructInvalid($number, $country, $validNumber, $expectedException)
|
||||||
{
|
{
|
||||||
/** @var PhoneNumberUtil|MockObject $phoneNumberUtilMock */
|
/** @var PhoneNumberUtil|MockObject $phoneNumberUtilMock */
|
||||||
$phoneNumberUtilMock = $this->getMockBuilder(PhoneNumberUtil::class)
|
$phoneNumberUtilMock = $this->getMockBuilder(PhoneNumberUtil::class)
|
||||||
->onlyMethods(['parse', 'format', 'isValidNumber', 'getNumberType'])
|
->onlyMethods(['parse', 'format', 'isValidNumber'])
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock();
|
||||||
if ($number === 'abc') {
|
if ($number === 'abc') {
|
||||||
|
@ -135,7 +120,6 @@ 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)
|
||||||
|
@ -149,27 +133,21 @@ class RecipientTest extends ApiTestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array[]
|
* @return string[][]
|
||||||
*/
|
*/
|
||||||
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, PhoneNumberType::MOBILE, InvalidArgumentException::class],
|
'empty number' => ['', 'DE', true, InvalidArgumentException::class],
|
||||||
'invalid country code' => [$phoneNumberFixture, 'DEX', true, PhoneNumberType::MOBILE, InvalidArgumentException::class],
|
'invalid country code' => [$this->phoneNumberFixture, 'DEX', true, InvalidArgumentException::class],
|
||||||
'unparsable' => ['abc', 'DE', true, PhoneNumberType::MOBILE, NumberParseException::class],
|
'unparsable' => ['abc', 'DE', true, NumberParseException::class],
|
||||||
'invalid number' => ['abcd', 'DE', false, PhoneNumberType::MOBILE, RecipientException::class],
|
'invalid number' => ['abc', 'DE', false, NumberParseException::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()
|
||||||
{
|
{
|
||||||
|
@ -181,65 +159,4 @@ 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,18 +21,16 @@ 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;
|
||||||
|
|
||||||
class SenderTest extends ApiTestCase
|
class SenderTest extends ApiTestCase
|
||||||
{
|
{
|
||||||
/** @var Sender|MockObject */
|
/** @var Sender */
|
||||||
public $sender;
|
public $sender;
|
||||||
|
|
||||||
private $phoneNumberFixture;
|
private $phoneNumberFixture = '015792300219';
|
||||||
private $phoneCountryFixture = 'DE';
|
private $phoneCountryFixture = 'DE';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -44,10 +42,6 @@ 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);
|
|
||||||
|
|
||||||
$this->sender = new Sender($this->phoneNumberFixture, $this->phoneCountryFixture);
|
$this->sender = new Sender($this->phoneNumberFixture, $this->phoneCountryFixture);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,10 +61,8 @@ 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($number, $country, $hasNumber)
|
public function testConstructValid()
|
||||||
{
|
{
|
||||||
/** @var PhoneNumberUtil|MockObject $phoneNumberUtilMock */
|
/** @var PhoneNumberUtil|MockObject $phoneNumberUtilMock */
|
||||||
$phoneNumberUtilMock = $this->getMockBuilder(PhoneNumberUtil::class)
|
$phoneNumberUtilMock = $this->getMockBuilder(PhoneNumberUtil::class)
|
||||||
|
@ -87,42 +79,27 @@ class SenderTest extends ApiTestCase
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock();
|
||||||
$senderMock->method('getPhoneNumberUtil')->willReturn($phoneNumberUtilMock);
|
$senderMock->method('getPhoneNumberUtil')->willReturn($phoneNumberUtilMock);
|
||||||
$senderMock->__construct($number, $country);
|
$senderMock->__construct($this->phoneNumberFixture, $this->phoneCountryFixture);
|
||||||
|
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
$hasNumber,
|
'4915792300219',
|
||||||
$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)
|
||||||
{
|
{
|
||||||
|
@ -132,14 +109,12 @@ class SenderTest extends ApiTestCase
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock();
|
||||||
if ($number === 'abc') {
|
if ($number === 'abc') {
|
||||||
$phoneNumberUtilMock->expects($this->exactly((int) ($country !== 'DEX')))->method('parse')
|
$phoneNumberUtilMock->method('parse')->willThrowException(new NumberParseException(0, 'message'));
|
||||||
->willThrowException(new NumberParseException(0, 'message'));
|
|
||||||
} else {
|
} else {
|
||||||
$phoneNumberUtilMock->expects($this->exactly((int) ($country !== 'DEX')))->method('parse')
|
$phoneNumberUtilMock->method('parse')->willReturn(new PhoneNumber());
|
||||||
->willReturn(new PhoneNumber());
|
|
||||||
}
|
}
|
||||||
$phoneNumberUtilMock->method('format')->willReturn($number);
|
$phoneNumberUtilMock->method('format')->willReturn($number);
|
||||||
$phoneNumberUtilMock->method('isValidNumber')->willReturn((bool) $validNumber);
|
$phoneNumberUtilMock->method('isValidNumber')->willReturn($validNumber);
|
||||||
|
|
||||||
/** @var Sender|MockObject $senderMock */
|
/** @var Sender|MockObject $senderMock */
|
||||||
$senderMock = $this->getMockBuilder(Sender::class)
|
$senderMock = $this->getMockBuilder(Sender::class)
|
||||||
|
@ -149,35 +124,25 @@ 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]
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array[]
|
* @return string[][]
|
||||||
*/
|
*/
|
||||||
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' => [$phoneNumberFixture, 'DEX', true, InvalidArgumentException::class],
|
'invalid country code' => [$this->phoneNumberFixture, 'DEX', true, InvalidArgumentException::class],
|
||||||
'unparsable' => ['abc', 'DE', true, NumberParseException::class],
|
'unparsable' => ['abc', 'DE', true, NumberParseException::class],
|
||||||
'invalid number' => ['abcd', 'DE', false, RecipientException::class],
|
'invalid number' => ['abc', 'DE', false, NumberParseException::class]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
* @covers \D3\LinkmobilityClient\ValueObject\Sender::getPhoneNumberUtil
|
|
||||||
*/
|
*/
|
||||||
public function testGetPhoneNumberUtil()
|
public function testGetPhoneNumberUtil()
|
||||||
{
|
{
|
||||||
|
@ -189,42 +154,4 @@ 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'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,13 +15,14 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace D3\LinkmobilityClient\Tests\ValueObject;
|
namespace D3\LinkmobilityClient\Tests\ValueObject;
|
||||||
|
|
||||||
|
use Assert\InvalidArgumentException;
|
||||||
|
use D3\LinkmobilityClient\Tests\ApiTestCase;
|
||||||
use D3\LinkmobilityClient\ValueObject\SmsBinaryMessage;
|
use D3\LinkmobilityClient\ValueObject\SmsBinaryMessage;
|
||||||
use Phlib\SmsLength\Exception\InvalidArgumentException;
|
|
||||||
use Phlib\SmsLength\SmsLength;
|
use Phlib\SmsLength\SmsLength;
|
||||||
use PHPUnit\Framework\MockObject\MockObject;
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
use ReflectionException;
|
use ReflectionException;
|
||||||
|
|
||||||
class SmsBinaryMessageTest extends SmsMessageAbstractTest
|
class SmsBinaryMessageTest extends ApiTestCase
|
||||||
{
|
{
|
||||||
/** @var SmsBinaryMessage */
|
/** @var SmsBinaryMessage */
|
||||||
public $message;
|
public $message;
|
||||||
|
@ -38,12 +39,20 @@ class SmsBinaryMessageTest extends SmsMessageAbstractTest
|
||||||
$this->message = new SmsBinaryMessage($this->messageFixture);
|
$this->message = new SmsBinaryMessage($this->messageFixture);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function tearDown(): void
|
||||||
|
{
|
||||||
|
parent::tearDown();
|
||||||
|
|
||||||
|
unset($this->message);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @return void
|
* @return void
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsBinaryMessage::__construct
|
|
||||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsMessageAbstract::__construct
|
|
||||||
*/
|
*/
|
||||||
public function testConstructValid()
|
public function testConstructValid()
|
||||||
{
|
{
|
||||||
|
@ -80,8 +89,6 @@ class SmsBinaryMessageTest extends SmsMessageAbstractTest
|
||||||
*
|
*
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
* @dataProvider constructInvalidDataProvider
|
* @dataProvider constructInvalidDataProvider
|
||||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsBinaryMessage::__construct
|
|
||||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsMessageAbstract::__construct
|
|
||||||
*/
|
*/
|
||||||
public function testConstructInvalid($binaryMessage, $valid, $expectedException)
|
public function testConstructInvalid($binaryMessage, $valid, $expectedException)
|
||||||
{
|
{
|
||||||
|
@ -93,7 +100,7 @@ class SmsBinaryMessageTest extends SmsMessageAbstractTest
|
||||||
if ($valid) {
|
if ($valid) {
|
||||||
$smsLengthMock->expects($this->never())->method('validate')->willReturn(true);
|
$smsLengthMock->expects($this->never())->method('validate')->willReturn(true);
|
||||||
} else {
|
} else {
|
||||||
$smsLengthMock->expects($this->atLeastOnce())->method('validate')->willThrowException(new InvalidArgumentException());
|
$smsLengthMock->expects($this->atLeastOnce())->method('validate')->willThrowException(new \Phlib\SmsLength\Exception\InvalidArgumentException());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var SmsBinaryMessage|MockObject $message */
|
/** @var SmsBinaryMessage|MockObject $message */
|
||||||
|
@ -115,11 +122,34 @@ class SmsBinaryMessageTest extends SmsMessageAbstractTest
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string[][]
|
||||||
|
*/
|
||||||
|
public function constructInvalidDataProvider(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'empty message' => ['', true, InvalidArgumentException::class],
|
||||||
|
'invalid sms message' => ['abc', false, \Phlib\SmsLength\Exception\InvalidArgumentException::class]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsBinaryMessage::chunkCount
|
*/
|
||||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsMessageAbstract::chunkCount
|
public function testGetSmsLengthInstance()
|
||||||
|
{
|
||||||
|
$this->assertInstanceOf(
|
||||||
|
SmsLength::class,
|
||||||
|
$this->callMethod(
|
||||||
|
$this->message,
|
||||||
|
'getSmsLength'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws ReflectionException
|
||||||
*/
|
*/
|
||||||
public function testGetChunkCount()
|
public function testGetChunkCount()
|
||||||
{
|
{
|
||||||
|
@ -135,9 +165,9 @@ class SmsBinaryMessageTest extends SmsMessageAbstractTest
|
||||||
|
|
||||||
/** @var SmsBinaryMessage|MockObject $message */
|
/** @var SmsBinaryMessage|MockObject $message */
|
||||||
$message = $this->getMockBuilder(SmsBinaryMessage::class)
|
$message = $this->getMockBuilder(SmsBinaryMessage::class)
|
||||||
->onlyMethods(['getSmsLength'])
|
->onlyMethods(['getSmsLength'])
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock();
|
||||||
$message->method('getSmsLength')->willReturn($smsLengthMock);
|
$message->method('getSmsLength')->willReturn($smsLengthMock);
|
||||||
|
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
|
@ -150,10 +180,7 @@ class SmsBinaryMessageTest extends SmsMessageAbstractTest
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsBinaryMessage::length
|
|
||||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsMessageAbstract::length
|
|
||||||
*/
|
*/
|
||||||
public function testGetSize()
|
public function testGetSize()
|
||||||
{
|
{
|
||||||
|
@ -184,10 +211,7 @@ class SmsBinaryMessageTest extends SmsMessageAbstractTest
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsBinaryMessage::getMessageContent
|
|
||||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsMessageAbstract::getMessageContent
|
|
||||||
*/
|
*/
|
||||||
public function testGetMessageContent()
|
public function testGetMessageContent()
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,65 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*
|
|
||||||
* https://www.d3data.de
|
|
||||||
*
|
|
||||||
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
|
||||||
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
|
|
||||||
* @link https://www.oxidmodule.com
|
|
||||||
*/
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace D3\LinkmobilityClient\Tests\ValueObject;
|
|
||||||
|
|
||||||
use Assert\InvalidArgumentException;
|
|
||||||
use D3\LinkmobilityClient\Tests\ApiTestCase;
|
|
||||||
use D3\LinkmobilityClient\ValueObject\SmsBinaryMessage;
|
|
||||||
use Phlib\SmsLength\SmsLength;
|
|
||||||
use ReflectionException;
|
|
||||||
|
|
||||||
abstract class SmsMessageAbstractTest extends ApiTestCase
|
|
||||||
{
|
|
||||||
public $message;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function tearDown(): void
|
|
||||||
{
|
|
||||||
parent::tearDown();
|
|
||||||
|
|
||||||
unset($this->message);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array[]
|
|
||||||
*/
|
|
||||||
public function constructInvalidDataProvider(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'empty message' => ['', true, InvalidArgumentException::class],
|
|
||||||
'invalid sms message' => ['abc', false, \Phlib\SmsLength\Exception\InvalidArgumentException::class],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @test
|
|
||||||
* @throws ReflectionException
|
|
||||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsBinaryMessage::getSmsLength
|
|
||||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsTextMessage::getSmsLength
|
|
||||||
*/
|
|
||||||
public function testGetSmsLengthInstance()
|
|
||||||
{
|
|
||||||
$this->assertInstanceOf(
|
|
||||||
SmsLength::class,
|
|
||||||
$this->callMethod(
|
|
||||||
$this->message,
|
|
||||||
'getSmsLength'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -21,7 +21,7 @@ use Phlib\SmsLength\SmsLength;
|
||||||
use PHPUnit\Framework\MockObject\MockObject;
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
use ReflectionException;
|
use ReflectionException;
|
||||||
|
|
||||||
class SmsTextMessageTest extends SmsMessageAbstractTest
|
class SmsTextMessageTest extends SmsBinaryMessageTest
|
||||||
{
|
{
|
||||||
/** @var SmsTextMessage */
|
/** @var SmsTextMessage */
|
||||||
public $message;
|
public $message;
|
||||||
|
@ -42,8 +42,6 @@ class SmsTextMessageTest extends SmsMessageAbstractTest
|
||||||
* @test
|
* @test
|
||||||
* @return void
|
* @return void
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsTextMessage::__construct
|
|
||||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsMessageAbstract::__construct
|
|
||||||
*/
|
*/
|
||||||
public function testConstructValid()
|
public function testConstructValid()
|
||||||
{
|
{
|
||||||
|
@ -80,8 +78,6 @@ class SmsTextMessageTest extends SmsMessageAbstractTest
|
||||||
*
|
*
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
* @dataProvider constructInvalidDataProvider
|
* @dataProvider constructInvalidDataProvider
|
||||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsTextMessage::__construct
|
|
||||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsMessageAbstract::__construct
|
|
||||||
*/
|
*/
|
||||||
public function testConstructInvalid($binaryMessage, $valid, $expectedException)
|
public function testConstructInvalid($binaryMessage, $valid, $expectedException)
|
||||||
{
|
{
|
||||||
|
@ -114,104 +110,4 @@ class SmsTextMessageTest extends SmsMessageAbstractTest
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @test
|
|
||||||
* @throws ReflectionException
|
|
||||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsTextMessage::chunkCount
|
|
||||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsMessageAbstract::chunkCount
|
|
||||||
*/
|
|
||||||
public function testGetChunkCount()
|
|
||||||
{
|
|
||||||
$expected = 2;
|
|
||||||
|
|
||||||
/** @var SmsLength|MockObject $smsLengthMock */
|
|
||||||
$smsLengthMock = $this->getMockBuilder(SmsLength::class)
|
|
||||||
->onlyMethods(['getMessageCount', 'validate'])
|
|
||||||
->disableOriginalConstructor()
|
|
||||||
->getMock();
|
|
||||||
$smsLengthMock->expects($this->once())->method('getMessageCount')->willReturn($expected);
|
|
||||||
$smsLengthMock->method('validate')->willReturn(true);
|
|
||||||
|
|
||||||
/** @var SmsTextMessage|MockObject $message */
|
|
||||||
$message = $this->getMockBuilder(SmsTextMessage::class)
|
|
||||||
->onlyMethods(['getSmsLength'])
|
|
||||||
->disableOriginalConstructor()
|
|
||||||
->getMock();
|
|
||||||
$message->method('getSmsLength')->willReturn($smsLengthMock);
|
|
||||||
|
|
||||||
$this->assertSame(
|
|
||||||
$expected,
|
|
||||||
$this->callMethod(
|
|
||||||
$message,
|
|
||||||
'chunkCount'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @test
|
|
||||||
* @throws ReflectionException
|
|
||||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsTextMessage::length
|
|
||||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsMessageAbstract::length
|
|
||||||
*/
|
|
||||||
public function testGetSize()
|
|
||||||
{
|
|
||||||
$expected = 55;
|
|
||||||
|
|
||||||
/** @var SmsLength|MockObject $smsLengthMock */
|
|
||||||
$smsLengthMock = $this->getMockBuilder(SmsLength::class)
|
|
||||||
->onlyMethods(['getSize', 'validate'])
|
|
||||||
->disableOriginalConstructor()
|
|
||||||
->getMock();
|
|
||||||
$smsLengthMock->expects($this->once())->method('getSize')->willReturn($expected);
|
|
||||||
$smsLengthMock->method('validate')->willReturn(true);
|
|
||||||
|
|
||||||
/** @var SmsTextMessage|MockObject $message */
|
|
||||||
$message = $this->getMockBuilder(SmsTextMessage::class)
|
|
||||||
->onlyMethods(['getSmsLength'])
|
|
||||||
->disableOriginalConstructor()
|
|
||||||
->getMock();
|
|
||||||
$message->method('getSmsLength')->willReturn($smsLengthMock);
|
|
||||||
|
|
||||||
$this->assertSame(
|
|
||||||
$expected,
|
|
||||||
$this->callMethod(
|
|
||||||
$message,
|
|
||||||
'length'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @test
|
|
||||||
* @throws ReflectionException
|
|
||||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsTextMessage::getMessageContent
|
|
||||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsMessageAbstract::getMessageContent
|
|
||||||
*/
|
|
||||||
public function testGetMessageContent()
|
|
||||||
{
|
|
||||||
/** @var SmsLength|MockObject $smsLengthMock */
|
|
||||||
$smsLengthMock = $this->getMockBuilder(SmsLength::class)
|
|
||||||
->onlyMethods(['validate'])
|
|
||||||
->disableOriginalConstructor()
|
|
||||||
->getMock();
|
|
||||||
$smsLengthMock->method('validate')->willReturn(true);
|
|
||||||
|
|
||||||
/** @var SmsTextMessage|MockObject $message */
|
|
||||||
$message = $this->getMockBuilder(SmsTextMessage::class)
|
|
||||||
->onlyMethods(['getSmsLength'])
|
|
||||||
->disableOriginalConstructor()
|
|
||||||
->getMock();
|
|
||||||
$message->method('getSmsLength')->willReturn($smsLengthMock);
|
|
||||||
$message->__construct($this->messageFixture);
|
|
||||||
|
|
||||||
$this->assertSame(
|
|
||||||
'testMessage',
|
|
||||||
$this->callMethod(
|
|
||||||
$message,
|
|
||||||
'getMessageContent'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,85 +0,0 @@
|
||||||
<?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
|
|
||||||
{
|
|
||||||
/** @var ValueObject|MockObject */
|
|
||||||
public $value;
|
|
||||||
|
|
||||||
public function setUp(): void
|
|
||||||
{
|
|
||||||
parent::setUp();
|
|
||||||
|
|
||||||
$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",
|
"name": "d3/linkmobility-php-client",
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"description": "PHP client for LINK Mobility API",
|
"description": "PHP client for LINK Mobility Austria API",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"LINK Mobility",
|
"LINK Mobility",
|
||||||
"php",
|
"php",
|
||||||
|
@ -21,20 +21,19 @@
|
||||||
"GPL-3.0-or-later"
|
"GPL-3.0-or-later"
|
||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^7.3 || ^8.0.3",
|
"php": "^7.0",
|
||||||
"beberlei/assert": "^3.3",
|
"beberlei/assert": "^2.9.9",
|
||||||
"guzzlehttp/guzzle": "^7.3",
|
"guzzlehttp/guzzle": "~6.2",
|
||||||
"psr/http-message": "^1.0 || ^2.0",
|
"psr/http-message": "~1.0",
|
||||||
"phlib/sms-length": "^2.0",
|
"symfony/options-resolver": "^4.4.37",
|
||||||
|
"phlib/sms-length": "^1.1.0 || ^2.0.0",
|
||||||
"giggsey/libphonenumber-for-php": "^8.12.50",
|
"giggsey/libphonenumber-for-php": "^8.12.50",
|
||||||
"caseyamcl/guzzle_retry_middleware": "^2.8",
|
|
||||||
"ext-json": "*"
|
"ext-json": "*"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"php": "^7.4 || ~8.0.3",
|
"php": "^7.2",
|
||||||
"phpunit/phpunit" : "^9.5",
|
"phpunit/phpunit" : "^8.0",
|
||||||
"friendsofphp/php-cs-fixer": "^3.9",
|
"friendsofphp/php-cs-fixer": "^2.0"
|
||||||
"phpstan/phpstan": "^1.8"
|
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
|
@ -43,9 +42,8 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "./vendor/bin/phpunit",
|
"test": "phpunit",
|
||||||
"check-style": "./vendor/bin/php-cs-fixer fix --verbose --dry-run",
|
"check-style": "./vendor/bin/php-cs-fixer fix --verbose --dry-run",
|
||||||
"fix-style": "./vendor/bin/php-cs-fixer fix --verbose",
|
"fix-style": "./vendor/bin/php-cs-fixer fix --verbose"
|
||||||
"check-code": "./vendor/bin/phpstan analyse -c phpstan.neon --no-progress --ansi"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
parameters:
|
|
||||||
paths:
|
|
||||||
- src
|
|
||||||
- Tests
|
|
||||||
level: 5
|
|
||||||
phpVersion: 70300
|
|
40
phpunit.xml
40
phpunit.xml
|
@ -1,20 +1,22 @@
|
||||||
<?xml version="1.0"?>
|
|
||||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<phpunit
|
||||||
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">
|
|
||||||
<coverage>
|
<testsuite name="tankerkoenig">
|
||||||
<include>
|
<directory>./Tests</directory>
|
||||||
<directory suffix=".php">src</directory>
|
</testsuite>
|
||||||
</include>
|
|
||||||
<report>
|
<filter>
|
||||||
<clover outputFile="build/logs/clover.xml"/>
|
<whitelist>
|
||||||
</report>
|
<directory suffix=".php">src</directory>
|
||||||
</coverage>
|
</whitelist>
|
||||||
<testsuite name="linkmobility">
|
</filter>
|
||||||
<directory>./Tests</directory>
|
|
||||||
</testsuite>
|
<logging>
|
||||||
<logging/>
|
<log type="coverage-clover" target="build/logs/clover.xml"/>
|
||||||
|
</logging>
|
||||||
|
|
||||||
</phpunit>
|
</phpunit>
|
||||||
|
|
|
@ -15,18 +15,14 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace D3\LinkmobilityClient;
|
namespace D3\LinkmobilityClient;
|
||||||
|
|
||||||
use Assert\InvalidArgumentException;
|
use D3\LinkmobilityClient\Exceptions\ApiException;
|
||||||
|
use D3\LinkmobilityClient\Exceptions\ExceptionMessages;
|
||||||
use D3\LinkmobilityClient\Request\RequestInterface;
|
use D3\LinkmobilityClient\Request\RequestInterface;
|
||||||
use D3\LinkmobilityClient\Url\Url;
|
|
||||||
use D3\LinkmobilityClient\Url\UrlInterface;
|
|
||||||
use GuzzleHttp\Client as GuzzleClient;
|
|
||||||
use GuzzleHttp\ClientInterface;
|
use GuzzleHttp\ClientInterface;
|
||||||
use GuzzleHttp\Exception\GuzzleException;
|
use GuzzleHttp\Exception\GuzzleException;
|
||||||
use GuzzleHttp\HandlerStack;
|
use InvalidArgumentException;
|
||||||
use GuzzleHttp\MessageFormatter;
|
|
||||||
use GuzzleHttp\Middleware;
|
|
||||||
use GuzzleRetry\GuzzleRetryMiddleware;
|
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
class Client
|
class Client
|
||||||
{
|
{
|
||||||
|
@ -34,32 +30,20 @@ class Client
|
||||||
public $apiUrl;
|
public $apiUrl;
|
||||||
public $requestClient;
|
public $requestClient;
|
||||||
|
|
||||||
|
private $logger;
|
||||||
|
|
||||||
public function __construct(string $accessToken, UrlInterface $apiUrl = null, ClientInterface $client = null)
|
public function __construct(string $accessToken, UrlInterface $apiUrl = null, ClientInterface $client = null)
|
||||||
{
|
{
|
||||||
$this->accessToken = $accessToken;
|
$this->accessToken = $accessToken;
|
||||||
$this->apiUrl = $apiUrl ?: new Url();
|
$this->apiUrl = $apiUrl ?: new Url();
|
||||||
$this->requestClient = $client ?: $this->getDefaultClient();
|
$this->requestClient = $client ?: new \GuzzleHttp\Client([ 'base_uri' => $this->apiUrl->getBaseUri() ]);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return GuzzleClient
|
|
||||||
*/
|
|
||||||
protected function getDefaultClient(): GuzzleClient
|
|
||||||
{
|
|
||||||
$handlerStack = HandlerStack::create();
|
|
||||||
$handlerStack->push($this->getLoggerMiddleware());
|
|
||||||
$handlerStack->push($this->getRetryMiddleware());
|
|
||||||
|
|
||||||
return new GuzzleClient( [
|
|
||||||
'base_uri' => $this->apiUrl->getBaseUri(),
|
|
||||||
'handler' => $handlerStack
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param RequestInterface $request
|
* @param RequestInterface $request
|
||||||
*
|
*
|
||||||
* @return Response\ResponseInterface
|
* @return Response\ResponseInterface
|
||||||
|
* @throws ApiException
|
||||||
* @throws GuzzleException
|
* @throws GuzzleException
|
||||||
* @throws InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
|
@ -78,47 +62,64 @@ class Client
|
||||||
* @param array $options
|
* @param array $options
|
||||||
*
|
*
|
||||||
* @return ResponseInterface
|
* @return ResponseInterface
|
||||||
|
* @throws ApiException
|
||||||
* @throws GuzzleException
|
* @throws GuzzleException
|
||||||
*/
|
*/
|
||||||
protected function rawRequest($url, string $method = RequestInterface::METHOD_GET, array $options = []): ResponseInterface
|
protected function rawRequest($url, string $method = RequestInterface::METHOD_GET, array $options = []): ResponseInterface
|
||||||
{
|
{
|
||||||
$options['headers']['Authorization'] = 'Bearer '.$this->accessToken;
|
$options['headers']['Authorization'] = 'Bearer '.$this->accessToken;
|
||||||
|
|
||||||
$response = $this->requestClient->request($method, $url, $options);
|
if ($this->hasLogger()) {
|
||||||
$response->getBody()->rewind();
|
$this->getLogger()->debug('request '.$url, $options);
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = $this->requestClient->request(
|
||||||
|
$method,
|
||||||
|
$url,
|
||||||
|
$options
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($response->getStatusCode() != 200) {
|
||||||
|
$message = sprintf(ExceptionMessages::NOK_REQUEST_RETURN, $url, $response->getStatusCode());
|
||||||
|
if ($this->hasLogger()) {
|
||||||
|
$this->getLogger()->error($message);
|
||||||
|
}
|
||||||
|
throw new ApiException($message);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->hasLogger()) {
|
||||||
|
$response->getBody()->rewind();
|
||||||
|
$this->getLogger()->debug('response', [$response->getBody()->getContents()]);
|
||||||
|
}
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return LoggerHandler
|
* @param mixed $logger
|
||||||
*/
|
|
||||||
public function getLoggerHandler(): LoggerHandler
|
|
||||||
{
|
|
||||||
return LoggerHandler::getInstance();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $loglevel
|
|
||||||
*
|
*
|
||||||
* @return callable
|
* @return Client
|
||||||
*/
|
*/
|
||||||
protected function getLoggerMiddleware(string $loglevel = 'debug'): callable
|
public function setLogger(LoggerInterface $logger): Client
|
||||||
{
|
{
|
||||||
return Middleware::log(
|
$this->logger = $logger;
|
||||||
$this->getLoggerHandler()->getLogger(),
|
|
||||||
new MessageFormatter(MessageFormatter::DEBUG),
|
return $this;
|
||||||
$loglevel
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return callable
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function getRetryMiddleware(): callable
|
public function hasLogger(): bool
|
||||||
{
|
{
|
||||||
return GuzzleRetryMiddleware::factory([
|
return $this->logger instanceof LoggerInterface;
|
||||||
'max_retry_attempts' => 3
|
}
|
||||||
]);
|
|
||||||
|
/**
|
||||||
|
* @return LoggerInterface|null
|
||||||
|
*/
|
||||||
|
public function getLogger()
|
||||||
|
{
|
||||||
|
return $this->hasLogger() ? $this->logger : null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,6 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace D3\LinkmobilityClient\Exceptions;
|
namespace D3\LinkmobilityClient\Exceptions;
|
||||||
|
|
||||||
class NoSenderDefinedException extends LinkmobilityException
|
class ApiException extends LinkmobilityException
|
||||||
{
|
{
|
||||||
}
|
}
|
|
@ -17,15 +17,11 @@ namespace D3\LinkmobilityClient\Exceptions;
|
||||||
|
|
||||||
class ExceptionMessages
|
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';
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,59 +0,0 @@
|
||||||
<?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 LoggerInterface $logger
|
|
||||||
*/
|
|
||||||
public function setLogger(LoggerInterface $logger)
|
|
||||||
{
|
|
||||||
$this->logger = $logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return LoggerInterface
|
|
||||||
*/
|
|
||||||
public function getLogger(): LoggerInterface
|
|
||||||
{
|
|
||||||
return $this->logger;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -16,8 +16,13 @@ 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
|
||||||
{
|
{
|
||||||
|
@ -31,15 +36,17 @@ class RecipientsList implements RecipientsListInterface, Iterator
|
||||||
*/
|
*/
|
||||||
private $recipients = [];
|
private $recipients = [];
|
||||||
|
|
||||||
/**
|
public function __construct(Client $client)
|
||||||
* @deprecated unused client parameter will remove
|
|
||||||
* @param Client|null $client
|
|
||||||
*/
|
|
||||||
public function __construct(Client $client = null)
|
|
||||||
{
|
{
|
||||||
if ($client) {
|
$this->setClient($client);
|
||||||
$this->setClient( $client );
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
|
* @return PhoneNumberUtil
|
||||||
|
*/
|
||||||
|
protected function getPhoneNumberUtil(): PhoneNumberUtil
|
||||||
|
{
|
||||||
|
return PhoneNumberUtil::getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -49,7 +56,34 @@ class RecipientsList implements RecipientsListInterface, Iterator
|
||||||
*/
|
*/
|
||||||
public function add(Recipient $recipient): RecipientsListInterface
|
public function add(Recipient $recipient): RecipientsListInterface
|
||||||
{
|
{
|
||||||
$this->recipients[ md5(serialize($recipient)) ] = $recipient;
|
$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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
@ -64,15 +98,12 @@ class RecipientsList implements RecipientsListInterface, Iterator
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getRecipients(): array
|
public function getRecipients(): array
|
||||||
{
|
{
|
||||||
return array_values(
|
return array_values(
|
||||||
array_map(
|
array_map(
|
||||||
function (Recipient $recipient) {
|
function (Recipient $recipient) {
|
||||||
return $recipient->getFormatted();
|
return $recipient->get();
|
||||||
},
|
},
|
||||||
$this->recipients
|
$this->recipients
|
||||||
)
|
)
|
||||||
|
@ -119,7 +150,6 @@ class RecipientsList implements RecipientsListInterface, Iterator
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated
|
|
||||||
* @return Client
|
* @return Client
|
||||||
*/
|
*/
|
||||||
public function getClient(): Client
|
public function getClient(): Client
|
||||||
|
@ -128,7 +158,6 @@ class RecipientsList implements RecipientsListInterface, Iterator
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated
|
|
||||||
* @param Client $client
|
* @param Client $client
|
||||||
*
|
*
|
||||||
* @return RecipientsList
|
* @return RecipientsList
|
||||||
|
|
|
@ -20,10 +20,6 @@ use D3\LinkmobilityClient\ValueObject\Recipient;
|
||||||
|
|
||||||
interface RecipientsListInterface
|
interface RecipientsListInterface
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @deprecated unused client parameter will remove
|
|
||||||
* @param Client $client
|
|
||||||
*/
|
|
||||||
public function __construct(Client $client);
|
public function __construct(Client $client);
|
||||||
|
|
||||||
public function add(Recipient $recipient): RecipientsListInterface;
|
public function add(Recipient $recipient): RecipientsListInterface;
|
||||||
|
@ -31,6 +27,4 @@ interface RecipientsListInterface
|
||||||
public function clearRecipents(): RecipientsListInterface;
|
public function clearRecipents(): RecipientsListInterface;
|
||||||
|
|
||||||
public function getRecipients(): array;
|
public function getRecipients(): array;
|
||||||
|
|
||||||
public function getRecipientsList(): array;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,9 +16,7 @@ declare(strict_types=1);
|
||||||
namespace D3\LinkmobilityClient\Request;
|
namespace D3\LinkmobilityClient\Request;
|
||||||
|
|
||||||
use Assert\Assert;
|
use Assert\Assert;
|
||||||
use Assert\InvalidArgumentException;
|
|
||||||
use D3\LinkmobilityClient\Client;
|
use D3\LinkmobilityClient\Client;
|
||||||
use D3\LinkmobilityClient\Exceptions\ExceptionMessages;
|
|
||||||
use D3\LinkmobilityClient\RecipientsList\RecipientsList;
|
use D3\LinkmobilityClient\RecipientsList\RecipientsList;
|
||||||
use D3\LinkmobilityClient\RecipientsList\RecipientsListInterface;
|
use D3\LinkmobilityClient\RecipientsList\RecipientsListInterface;
|
||||||
use D3\LinkmobilityClient\Response\ResponseInterface;
|
use D3\LinkmobilityClient\Response\ResponseInterface;
|
||||||
|
@ -26,7 +24,9 @@ use D3\LinkmobilityClient\ValueObject\Recipient;
|
||||||
use D3\LinkmobilityClient\ValueObject\Sender;
|
use D3\LinkmobilityClient\ValueObject\Sender;
|
||||||
use D3\LinkmobilityClient\ValueObject\SmsMessageAbstract;
|
use D3\LinkmobilityClient\ValueObject\SmsMessageAbstract;
|
||||||
use D3\LinkmobilityClient\ValueObject\SmsMessageInterface;
|
use D3\LinkmobilityClient\ValueObject\SmsMessageInterface;
|
||||||
|
use D3\LinkmobilityClient\ValueObject\StringValueObject;
|
||||||
use GuzzleHttp\RequestOptions;
|
use GuzzleHttp\RequestOptions;
|
||||||
|
use InvalidArgumentException;
|
||||||
|
|
||||||
abstract class Request implements RequestInterface
|
abstract class Request implements RequestInterface
|
||||||
{
|
{
|
||||||
|
@ -106,7 +106,7 @@ abstract class Request implements RequestInterface
|
||||||
private $test = false;
|
private $test = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var int
|
* @var bool
|
||||||
*/
|
*/
|
||||||
private $maxSmsPerMessage = 0;
|
private $maxSmsPerMessage = 0;
|
||||||
|
|
||||||
|
@ -118,12 +118,9 @@ abstract class Request implements RequestInterface
|
||||||
$this->recipientsList = new RecipientsList($client);
|
$this->recipientsList = new RecipientsList($client);
|
||||||
$this->setMessage($message);
|
$this->setMessage($message);
|
||||||
$this->setClient($client);
|
$this->setClient($client);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
return $this;
|
||||||
* @return string
|
}
|
||||||
*/
|
|
||||||
abstract public function getUri(): string;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
|
@ -138,7 +135,7 @@ abstract class Request implements RequestInterface
|
||||||
Assert::that($this->getOptions())->isArray();
|
Assert::that($this->getOptions())->isArray();
|
||||||
|
|
||||||
Assert::that($this->getRecipientsList())->isInstanceOf(RecipientsList::class)->notEmpty();
|
Assert::that($this->getRecipientsList())->isInstanceOf(RecipientsList::class)->notEmpty();
|
||||||
Assert::that($this->getRecipientsList()->getRecipients())->notEmpty(ExceptionMessages::EMPTY_RECIPIENT_LIST);
|
Assert::that($this->getRecipientsList()->getRecipients())->notEmpty('request must contain a valid recipient');
|
||||||
Assert::thatAll($this->getRecipientsList())->isInstanceOf(Recipient::class)->notEmpty();
|
Assert::thatAll($this->getRecipientsList())->isInstanceOf(Recipient::class)->notEmpty();
|
||||||
|
|
||||||
// optional properties
|
// optional properties
|
||||||
|
@ -166,7 +163,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()
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,18 +194,18 @@ 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()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param SmsMessageInterface $message
|
* @param StringValueObject $message
|
||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function setMessage(SmsMessageInterface $message): Request
|
public function setMessage(StringValueObject $message): Request
|
||||||
{
|
{
|
||||||
$this->message = $message;
|
$this->message = $message;
|
||||||
|
|
||||||
|
@ -277,7 +274,7 @@ abstract class Request implements RequestInterface
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getClientMessageId(): ?string
|
public function getClientMessageId()
|
||||||
{
|
{
|
||||||
return $this->clientMessageId;
|
return $this->clientMessageId;
|
||||||
}
|
}
|
||||||
|
@ -303,7 +300,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
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -373,7 +370,7 @@ abstract class Request implements RequestInterface
|
||||||
/**
|
/**
|
||||||
* @return string|null
|
* @return string|null
|
||||||
*/
|
*/
|
||||||
public function getNotificationCallbackUrl(): ?string
|
public function getNotificationCallbackUrl()
|
||||||
{
|
{
|
||||||
return $this->notificationCallbackUrl;
|
return $this->notificationCallbackUrl;
|
||||||
}
|
}
|
||||||
|
@ -393,7 +390,7 @@ abstract class Request implements RequestInterface
|
||||||
/**
|
/**
|
||||||
* @return int|null
|
* @return int|null
|
||||||
*/
|
*/
|
||||||
public function getPriority(): ?int
|
public function getPriority()
|
||||||
{
|
{
|
||||||
return $this->priority;
|
return $this->priority;
|
||||||
}
|
}
|
||||||
|
@ -419,7 +416,7 @@ abstract class Request implements RequestInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool
|
* @return bool|null
|
||||||
*/
|
*/
|
||||||
public function doSendAsFlashSms(): bool
|
public function doSendAsFlashSms(): bool
|
||||||
{
|
{
|
||||||
|
@ -441,7 +438,7 @@ abstract class Request implements RequestInterface
|
||||||
/**
|
/**
|
||||||
* @return Sender|null
|
* @return Sender|null
|
||||||
*/
|
*/
|
||||||
public function getSenderAddress(): ?Sender
|
public function getSenderAddress()
|
||||||
{
|
{
|
||||||
return $this->senderAddress;
|
return $this->senderAddress;
|
||||||
}
|
}
|
||||||
|
@ -461,9 +458,9 @@ abstract class Request implements RequestInterface
|
||||||
/**
|
/**
|
||||||
* @return string|null
|
* @return string|null
|
||||||
*/
|
*/
|
||||||
public function getSenderAddressType(): ?string
|
public function getSenderAddressType()
|
||||||
{
|
{
|
||||||
return $this->getSenderAddress() && $this->getSenderAddress()->get() ? $this->senderAddressType : null;
|
return $this->senderAddressType;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -475,7 +472,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
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -494,7 +491,7 @@ abstract class Request implements RequestInterface
|
||||||
/**
|
/**
|
||||||
* @return int|null
|
* @return int|null
|
||||||
*/
|
*/
|
||||||
public function getValidityPeriode(): ?int
|
public function getValidityPeriode()
|
||||||
{
|
{
|
||||||
return $this->validityPeriode;
|
return $this->validityPeriode;
|
||||||
}
|
}
|
||||||
|
@ -520,7 +517,6 @@ 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
|
||||||
{
|
{
|
||||||
|
|
|
@ -15,16 +15,14 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace D3\LinkmobilityClient\Request;
|
namespace D3\LinkmobilityClient\Request;
|
||||||
|
|
||||||
use Assert\InvalidArgumentException;
|
|
||||||
use D3\LinkmobilityClient\Client;
|
use D3\LinkmobilityClient\Client;
|
||||||
use D3\LinkmobilityClient\RecipientsList\RecipientsListInterface;
|
|
||||||
use D3\LinkmobilityClient\ValueObject\SmsMessageInterface;
|
use D3\LinkmobilityClient\ValueObject\SmsMessageInterface;
|
||||||
|
use InvalidArgumentException;
|
||||||
use Psr\Http\Message\ResponseInterface as PsrResponseInterface;
|
use Psr\Http\Message\ResponseInterface as PsrResponseInterface;
|
||||||
use D3\LinkmobilityClient\Response\ResponseInterface as LMResponseInterface;
|
use D3\LinkmobilityClient\Response\ResponseInterface as LMResponseInterface;
|
||||||
|
|
||||||
interface RequestInterface
|
interface RequestInterface
|
||||||
{
|
{
|
||||||
// @codeCoverageIgnoreStart
|
|
||||||
public const METHOD_GET = 'GET';
|
public const METHOD_GET = 'GET';
|
||||||
public const METHOD_POST = 'POST';
|
public const METHOD_POST = 'POST';
|
||||||
public const METHOD_PUT = 'PUT';
|
public const METHOD_PUT = 'PUT';
|
||||||
|
@ -43,20 +41,10 @@ interface RequestInterface
|
||||||
public const SENDERADDRESSTYPE_INTERNATIONAL = 'international';
|
public const SENDERADDRESSTYPE_INTERNATIONAL = 'international';
|
||||||
public const SENDERADDRESSTYPE_ALPHANUMERIC = 'alphanumeric';
|
public const SENDERADDRESSTYPE_ALPHANUMERIC = 'alphanumeric';
|
||||||
public const SENDERADDRESSTYPE_SHORTCODE = 'shortcode';
|
public const SENDERADDRESSTYPE_SHORTCODE = 'shortcode';
|
||||||
// @codeCoverageIgnoreEnd
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param SmsMessageInterface $message
|
|
||||||
* @param Client $client
|
|
||||||
*/
|
|
||||||
public function __construct(SmsMessageInterface $message, 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
|
* Must return the HTTP verb for this request, i.e. GET, POST, PUT
|
||||||
|
@ -65,18 +53,6 @@ interface RequestInterface
|
||||||
*/
|
*/
|
||||||
public function getMethod(): string;
|
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
|
* Must return the URI for the request with a leading slash, i.e. /messages.json
|
||||||
*
|
*
|
||||||
|
@ -105,11 +81,6 @@ interface RequestInterface
|
||||||
*/
|
*/
|
||||||
public function getResponseInstance(PsrResponseInterface $rawResponse): LMResponseInterface;
|
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)
|
* Must return the options for this request. If there are none, return [] (empty array)
|
||||||
*
|
*
|
||||||
|
|
|
@ -72,7 +72,7 @@ abstract class Response implements ResponseInterface
|
||||||
/**
|
/**
|
||||||
* @return string|null
|
* @return string|null
|
||||||
*/
|
*/
|
||||||
public function getClientMessageId(): ?string
|
public function getClientMessageId()
|
||||||
{
|
{
|
||||||
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(): ?string
|
public function getTransferId()
|
||||||
{
|
{
|
||||||
return $this->getContent()[self::TRANSFERID];
|
return $this->getContent()[self::TRANSFERID];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return int
|
* @return string|null
|
||||||
*/
|
*/
|
||||||
public function getSmsCount(): int
|
public function getSmsCount(): int
|
||||||
{
|
{
|
||||||
|
|
|
@ -16,10 +16,9 @@ declare(strict_types=1);
|
||||||
namespace D3\LinkmobilityClient\SMS;
|
namespace D3\LinkmobilityClient\SMS;
|
||||||
|
|
||||||
use Assert\Assert;
|
use Assert\Assert;
|
||||||
use Assert\InvalidArgumentException;
|
|
||||||
use D3\LinkmobilityClient\Request\Request;
|
use D3\LinkmobilityClient\Request\Request;
|
||||||
use D3\LinkmobilityClient\Url\Url;
|
|
||||||
use D3\LinkmobilityClient\ValueObject\SmsBinaryMessage;
|
use D3\LinkmobilityClient\ValueObject\SmsBinaryMessage;
|
||||||
|
use InvalidArgumentException;
|
||||||
|
|
||||||
class BinaryRequest extends Request implements SmsRequestInterface
|
class BinaryRequest extends Request implements SmsRequestInterface
|
||||||
{
|
{
|
||||||
|
@ -28,7 +27,7 @@ class BinaryRequest extends Request implements SmsRequestInterface
|
||||||
*/
|
*/
|
||||||
public function getUri(): string
|
public function getUri(): string
|
||||||
{
|
{
|
||||||
return (new Url())->getBinarySmsUri();
|
return '/rest/smsmessaging/binary';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRawBody(): array
|
public function getRawBody(): array
|
||||||
|
@ -36,7 +35,7 @@ class BinaryRequest extends Request implements SmsRequestInterface
|
||||||
return array_merge(
|
return array_merge(
|
||||||
parent::getRawBody(),
|
parent::getRawBody(),
|
||||||
[
|
[
|
||||||
'userDataHeaderPresent' => true,
|
'userDataHeaderPresent' => true
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,15 +20,21 @@ 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 implements RequestFactoryInterface
|
class RequestFactory
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @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;
|
||||||
|
@ -40,7 +46,7 @@ class RequestFactory implements RequestFactoryInterface
|
||||||
*/
|
*/
|
||||||
public function getSmsRequest(): SmsRequestInterface
|
public function getSmsRequest(): SmsRequestInterface
|
||||||
{
|
{
|
||||||
if ($this->getSmsLength()->getEncoding() === SmsLength::ENCODING_7BIT) {
|
if ($this->getSmsLength()->getEncoding() === self::GSM_7BIT) {
|
||||||
$message = new SmsTextMessage($this->message);
|
$message = new SmsTextMessage($this->message);
|
||||||
return new TextRequest($message, $this->client);
|
return new TextRequest($message, $this->client);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,11 +15,9 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace D3\LinkmobilityClient\SMS;
|
namespace D3\LinkmobilityClient\SMS;
|
||||||
|
|
||||||
use D3\LinkmobilityClient\Client;
|
|
||||||
|
|
||||||
interface RequestFactoryInterface
|
interface RequestFactoryInterface
|
||||||
{
|
{
|
||||||
public function __construct($message, Client $client);
|
public function __construct($message);
|
||||||
|
|
||||||
public function getSmsRequest(): SmsRequestInterface;
|
public function getRequest(): SmsRequestInterface;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,8 +15,6 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace D3\LinkmobilityClient\SMS;
|
namespace D3\LinkmobilityClient\SMS;
|
||||||
|
|
||||||
use D3\LinkmobilityClient\Response\Response as BaseResponse;
|
class Response extends \D3\LinkmobilityClient\Response\Response
|
||||||
|
|
||||||
class Response extends BaseResponse
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,10 +16,9 @@ declare(strict_types=1);
|
||||||
namespace D3\LinkmobilityClient\SMS;
|
namespace D3\LinkmobilityClient\SMS;
|
||||||
|
|
||||||
use Assert\Assert;
|
use Assert\Assert;
|
||||||
use Assert\InvalidArgumentException;
|
|
||||||
use D3\LinkmobilityClient\Request\Request;
|
use D3\LinkmobilityClient\Request\Request;
|
||||||
use D3\LinkmobilityClient\Url\Url;
|
|
||||||
use D3\LinkmobilityClient\ValueObject\SmsTextMessage;
|
use D3\LinkmobilityClient\ValueObject\SmsTextMessage;
|
||||||
|
use InvalidArgumentException;
|
||||||
|
|
||||||
class TextRequest extends Request implements SmsRequestInterface
|
class TextRequest extends Request implements SmsRequestInterface
|
||||||
{
|
{
|
||||||
|
@ -28,7 +27,7 @@ class TextRequest extends Request implements SmsRequestInterface
|
||||||
*/
|
*/
|
||||||
public function getUri(): string
|
public function getUri(): string
|
||||||
{
|
{
|
||||||
return (new Url())->getTextSmsUri();
|
return '/rest/smsmessaging/text';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace D3\LinkmobilityClient\Url;
|
namespace D3\LinkmobilityClient;
|
||||||
|
|
||||||
class Url implements UrlInterface
|
class Url implements UrlInterface
|
||||||
{
|
{
|
||||||
|
@ -26,20 +26,4 @@ class Url implements UrlInterface
|
||||||
{
|
{
|
||||||
return $this->baseUri;
|
return $this->baseUri;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getTextSmsUri(): string
|
|
||||||
{
|
|
||||||
return '/rest/smsmessaging/text';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getBinarySmsUri(): string
|
|
||||||
{
|
|
||||||
return '/rest/smsmessaging/binary';
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -13,13 +13,9 @@
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace D3\LinkmobilityClient\Url;
|
namespace D3\LinkmobilityClient;
|
||||||
|
|
||||||
interface UrlInterface
|
interface UrlInterface
|
||||||
{
|
{
|
||||||
public function getBaseUri(): string;
|
public function getBaseUri(): string;
|
||||||
|
|
||||||
public function getTextSmsUri(): string;
|
|
||||||
|
|
||||||
public function getBinarySmsUri(): string;
|
|
||||||
}
|
}
|
|
@ -16,24 +16,12 @@ declare(strict_types=1);
|
||||||
namespace D3\LinkmobilityClient\ValueObject;
|
namespace D3\LinkmobilityClient\ValueObject;
|
||||||
|
|
||||||
use Assert\Assert;
|
use Assert\Assert;
|
||||||
use Assert\InvalidArgumentException;
|
|
||||||
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
|
||||||
*/
|
*/
|
||||||
|
@ -44,29 +32,15 @@ class Recipient extends StringValueObject
|
||||||
* @param string $iso2CountryCode
|
* @param string $iso2CountryCode
|
||||||
*
|
*
|
||||||
* @throws NumberParseException
|
* @throws NumberParseException
|
||||||
* @throws RecipientException
|
|
||||||
* @throws InvalidArgumentException
|
|
||||||
*/
|
*/
|
||||||
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();
|
||||||
|
|
||||||
$phoneNumber = $phoneUtil->parse($number, strtoupper($iso2CountryCode));
|
$phoneNumber = $phoneUtil->parse($number, strtoupper($iso2CountryCode));
|
||||||
$number = $phoneUtil->format($phoneNumber, PhoneNumberFormat::E164);
|
$number = ltrim($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;
|
||||||
|
@ -87,9 +61,4 @@ class Recipient extends StringValueObject
|
||||||
{
|
{
|
||||||
return $this->countryCode;
|
return $this->countryCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFormatted(): string
|
|
||||||
{
|
|
||||||
return ltrim(parent::getFormatted(), '+');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,49 +16,35 @@ declare(strict_types=1);
|
||||||
namespace D3\LinkmobilityClient\ValueObject;
|
namespace D3\LinkmobilityClient\ValueObject;
|
||||||
|
|
||||||
use Assert\Assert;
|
use Assert\Assert;
|
||||||
use Assert\InvalidArgumentException;
|
|
||||||
use D3\LinkmobilityClient\Exceptions\ExceptionMessages;
|
use D3\LinkmobilityClient\Exceptions\ExceptionMessages;
|
||||||
use D3\LinkmobilityClient\Exceptions\NoSenderDefinedException;
|
|
||||||
use D3\LinkmobilityClient\Exceptions\RecipientException;
|
use D3\LinkmobilityClient\Exceptions\RecipientException;
|
||||||
use D3\LinkmobilityClient\LoggerHandler;
|
|
||||||
use libphonenumber\NumberParseException;
|
use libphonenumber\NumberParseException;
|
||||||
use libphonenumber\PhoneNumberFormat;
|
use libphonenumber\PhoneNumberFormat;
|
||||||
use libphonenumber\PhoneNumberUtil;
|
use libphonenumber\PhoneNumberUtil;
|
||||||
|
|
||||||
class Sender extends ValueObject
|
class Sender extends StringValueObject
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @param string|null $number
|
* @param string $number
|
||||||
* @param string|null $iso2CountryCode
|
* @param string $iso2CountryCode
|
||||||
*
|
*
|
||||||
* @throws NumberParseException
|
|
||||||
* @throws RecipientException
|
* @throws RecipientException
|
||||||
* @throws InvalidArgumentException
|
* @throws NumberParseException
|
||||||
*/
|
*/
|
||||||
public function __construct(string $number = null, string $iso2CountryCode = null)
|
public function __construct(string $number, string $iso2CountryCode)
|
||||||
{
|
{
|
||||||
try {
|
Assert::that($iso2CountryCode)->string()->length(2);
|
||||||
if (is_null($number) || is_null($iso2CountryCode)) {
|
|
||||||
throw new NoSenderDefinedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
Assert::that($iso2CountryCode)->string()->length(2);
|
$phoneUtil = $this->getPhoneNumberUtil();
|
||||||
|
|
||||||
$phoneUtil = $this->getPhoneNumberUtil();
|
$phoneNumber = $phoneUtil->parse($number, strtoupper($iso2CountryCode));
|
||||||
|
$number = ltrim($phoneUtil->format($phoneNumber, PhoneNumberFormat::E164), '+');
|
||||||
|
|
||||||
$phoneNumber = $phoneUtil->parse($number, strtoupper($iso2CountryCode));
|
if (false === $phoneUtil->isValidNumber($phoneNumber)) {
|
||||||
$number = $phoneUtil->format($phoneNumber, PhoneNumberFormat::E164);
|
throw new RecipientException(ExceptionMessages::INVALID_SENDER);
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -69,8 +55,11 @@ class Sender extends ValueObject
|
||||||
return PhoneNumberUtil::getInstance();
|
return PhoneNumberUtil::getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFormatted(): string
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getFormatted()
|
||||||
{
|
{
|
||||||
return ltrim(parent::getFormatted(), '+');
|
return parent::getFormatted();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ class SmsBinaryMessage extends SmsMessageAbstract
|
||||||
public function getMessageContent()
|
public function getMessageContent()
|
||||||
{
|
{
|
||||||
return str_split(
|
return str_split(
|
||||||
base64_encode(parent::getMessageContent()),
|
base64_encode($this->get()),
|
||||||
SmsLength::MAXIMUM_CHARACTERS_UCS2_SINGLE
|
SmsLength::MAXIMUM_CHARACTERS_UCS2_SINGLE
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,9 +43,6 @@ 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,7 +15,7 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace D3\LinkmobilityClient\ValueObject;
|
namespace D3\LinkmobilityClient\ValueObject;
|
||||||
|
|
||||||
use Assert\InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
|
|
||||||
class SmsTextMessage extends SmsMessageAbstract
|
class SmsTextMessage extends SmsMessageAbstract
|
||||||
{
|
{
|
||||||
|
|
|
@ -15,8 +15,17 @@ 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 __construct(string $number)
|
||||||
|
{
|
||||||
|
Assert::that($number)->notEmpty();
|
||||||
|
|
||||||
|
$this->value = $number;
|
||||||
|
}
|
||||||
|
|
||||||
public function __toString()
|
public function __toString()
|
||||||
{
|
{
|
||||||
return $this->get();
|
return $this->get();
|
||||||
|
@ -26,4 +35,9 @@ abstract class StringValueObject extends ValueObject
|
||||||
{
|
{
|
||||||
return $this->value;
|
return $this->value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getFormatted()
|
||||||
|
{
|
||||||
|
return $this->get();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,31 +15,7 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace D3\LinkmobilityClient\ValueObject;
|
namespace D3\LinkmobilityClient\ValueObject;
|
||||||
|
|
||||||
use Assert\Assert;
|
|
||||||
use Assert\InvalidArgumentException;
|
|
||||||
|
|
||||||
abstract class ValueObject
|
abstract class ValueObject
|
||||||
{
|
{
|
||||||
protected $value;
|
protected $value;
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $number
|
|
||||||
* @throws InvalidArgumentException
|
|
||||||
*/
|
|
||||||
public function __construct(string $number)
|
|
||||||
{
|
|
||||||
Assert::that($number)->notEmpty();
|
|
||||||
|
|
||||||
$this->value = $number;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function get()
|
|
||||||
{
|
|
||||||
return $this->value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getFormatted(): string
|
|
||||||
{
|
|
||||||
return $this->get();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue