Compare commits
27 Commits
Author | SHA1 | Date | |
---|---|---|---|
8ee6b780a4
|
|||
889584f5c8
|
|||
14a26a602b
|
|||
e8da35995e
|
|||
958ed9e83d
|
|||
1e2582a76b
|
|||
a50567fd0c
|
|||
19f5fca18a
|
|||
186bb2d622
|
|||
6c5a83a8a8
|
|||
54cfb2645c
|
|||
95384c5eba
|
|||
a8756c7ade
|
|||
df33a97084
|
|||
222770bec9
|
|||
8f70d40640
|
|||
cd4e3b6277
|
|||
0d589f3878
|
|||
3932246fbd
|
|||
3338d70562
|
|||
229d961bb8
|
|||
fed8040fcb
|
|||
b33b6081ad
|
|||
d07eb1f694
|
|||
c8ca412c14
|
|||
ff0784ce46
|
|||
7e43fa1537
|
@ -6,7 +6,7 @@ $finder = PhpCsFixer\Finder::create()
|
|||||||
|
|
||||||
$config = new PhpCsFixer\Config();
|
$config = new PhpCsFixer\Config();
|
||||||
return $config->setRules([
|
return $config->setRules([
|
||||||
'@PHP70Migration' => true,
|
'@PHP73Migration' => true,
|
||||||
'@PSR12' => true
|
'@PSR12' => true
|
||||||
])
|
])
|
||||||
->setFinder($finder)
|
->setFinder($finder)
|
||||||
|
60
CHANGELOG.md
60
CHANGELOG.md
@ -4,16 +4,62 @@ 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/),
|
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).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
## [Unreleased](https://git.d3data.de/D3Private/linkmobility-php-client/compare/1.3.1...rel_1.x)
|
## [Unreleased](https://git.d3data.de/D3Public/linkmobility-php-client/compare/2.2.0...rel_2.x)
|
||||||
|
|
||||||
## [1.3.1](https://git.d3data.de/D3Private/linkmobility-php-client/compare/1.3.0...1.3.1) - 2022-07-28
|
## [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
|
### Changed
|
||||||
- improve code quality
|
- improve code quality
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- wrong return type of LoggerHandler::getInstance
|
- wrong return type of LoggerHandler::getInstance
|
||||||
|
|
||||||
## [1.3.0](https://git.d3data.de/D3Private/linkmobility-php-client/compare/1.2.1...1.3.0) - 2022-07-18
|
## [1.3.0](https://git.d3data.de/D3Public/linkmobility-php-client/compare/1.2.1...1.3.0) - 2022-07-18
|
||||||
### Added
|
### Added
|
||||||
- tests added
|
- tests added
|
||||||
|
|
||||||
@ -21,12 +67,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- tests use generated example phone numbers
|
- tests use generated example phone numbers
|
||||||
- move recipient checks from list to recipient itself
|
- move recipient checks from list to recipient itself
|
||||||
|
|
||||||
## [1.2.1](https://git.d3data.de/D3Private/linkmobility-php-client/compare/1.2.0...1.2.1) - 2022-07-15
|
## [1.2.1](https://git.d3data.de/D3Public/linkmobility-php-client/compare/1.2.0...1.2.1) - 2022-07-15
|
||||||
### Changed
|
### Changed
|
||||||
- extend log messages
|
- extend log messages
|
||||||
- sanitize special phone number format before request
|
- sanitize special phone number format before request
|
||||||
|
|
||||||
## [1.2.0](https://git.d3data.de/D3Private/linkmobility-php-client/compare/1.1.0...1.2.0) - 2022-07-14
|
## [1.2.0](https://git.d3data.de/D3Public/linkmobility-php-client/compare/1.1.0...1.2.0) - 2022-07-14
|
||||||
### Added
|
### Added
|
||||||
- collect exception messages in a class
|
- collect exception messages in a class
|
||||||
- collect URI parts in a class
|
- collect URI parts in a class
|
||||||
@ -36,14 +82,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- assign sender address type only if sender is set
|
- assign sender address type only if sender is set
|
||||||
- extract logger handler from client
|
- extract logger handler from client
|
||||||
|
|
||||||
## [1.1.0](https://git.d3data.de/D3Private/linkmobility-php-client/compare/1.0.0...1.1.0) - 2022-07-13
|
## [1.1.0](https://git.d3data.de/D3Public/linkmobility-php-client/compare/1.0.0...1.1.0) - 2022-07-13
|
||||||
### Added
|
### Added
|
||||||
- make installable in PHP 8
|
- make installable in PHP 8
|
||||||
|
|
||||||
### Removed
|
### Removed
|
||||||
- remove unused dependency
|
- remove unused dependency
|
||||||
|
|
||||||
## [1.0.0](https://git.d3data.de/D3Private/linkmobility-php-client/releases/tag/1.0.0) - 2022-07-13
|
## [1.0.0](https://git.d3data.de/D3Public/linkmobility-php-client/releases/tag/1.0.0) - 2022-07-13
|
||||||
### Added
|
### Added
|
||||||
- initial implementation
|
- initial implementation
|
||||||
- SMS requests (text or binary)
|
- SMS requests (text or binary)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
[](README.md)
|
[](README.md)
|
||||||
[](README.en.md)
|
[](README.en.md)
|
||||||
|
|
||||||
# LINK Mobility Austria PHP API Client
|
# LINK Mobility PHP API Client
|
||||||
|
|
||||||
[LINK Mobility](https://www.linkmobility.de/) provides a service for sending mobile messages (SMS, Whatsapp, RCS, Chatbot, ...).
|
[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 Client('personal accesstoken');
|
$client = new \D3\LinkmobilityClient\Client('personal accesstoken');
|
||||||
$client->setLogger($logger); // optional
|
\D3\LinkmobilityClient\LoggerHandler::getInstance()->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)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
[](README.md)
|
[](README.md)
|
||||||
[](README.en.md)
|
[](README.en.md)
|
||||||
|
|
||||||
# LINK Mobility Austria PHP API Client
|
# LINK Mobility PHP API Client
|
||||||
|
|
||||||
[LINK Mobility](https://www.linkmobility.de/) stellt einen Service zum Versenden von mobilen Nachrichten (SMS, Whatsapp, RCS, Chatbot, ...) zur VerfĂĽgung.
|
[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 Client('personal accesstoken');
|
$client = new \D3\LinkmobilityClient\Client('personal accesstoken');
|
||||||
$client->setLogger($logger); // optional
|
\D3\LinkmobilityClient\LoggerHandler::getInstance()->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)
|
||||||
|
@ -31,7 +31,7 @@ abstract class ApiTestCase extends TestCase
|
|||||||
* @return mixed
|
* @return mixed
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
*/
|
*/
|
||||||
public function callMethod(object $object, string $methodName, array $arguments = [])
|
public function callMethod($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 $object, string $valueName, $value)
|
public function setValue($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 $object, string $valueName)
|
public function getValue($object, string $valueName)
|
||||||
{
|
{
|
||||||
$reflection = new ReflectionClass($object);
|
$reflection = new ReflectionClass($object);
|
||||||
$property = $reflection->getProperty($valueName);
|
$property = $reflection->getProperty($valueName);
|
||||||
|
@ -17,7 +17,6 @@ namespace D3\LinkmobilityClient\Tests;
|
|||||||
|
|
||||||
use Assert\InvalidArgumentException;
|
use Assert\InvalidArgumentException;
|
||||||
use D3\LinkmobilityClient\Client;
|
use D3\LinkmobilityClient\Client;
|
||||||
use D3\LinkmobilityClient\Exceptions\ApiException;
|
|
||||||
use D3\LinkmobilityClient\LoggerHandler;
|
use D3\LinkmobilityClient\LoggerHandler;
|
||||||
use D3\LinkmobilityClient\Request\RequestInterface;
|
use D3\LinkmobilityClient\Request\RequestInterface;
|
||||||
use D3\LinkmobilityClient\Response\Response;
|
use D3\LinkmobilityClient\Response\Response;
|
||||||
@ -27,11 +26,9 @@ use D3\LinkmobilityClient\Url\Url;
|
|||||||
use D3\LinkmobilityClient\Url\UrlInterface;
|
use D3\LinkmobilityClient\Url\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
|
||||||
@ -96,10 +93,32 @@ 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
|
||||||
@ -167,47 +186,26 @@ 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 $okStatus
|
|
||||||
* @return void
|
* @return void
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
* @dataProvider rawRequestDataProvider
|
|
||||||
* @covers \D3\LinkmobilityClient\Client::rawRequest
|
* @covers \D3\LinkmobilityClient\Client::rawRequest
|
||||||
*/
|
*/
|
||||||
public function testRawRequest($okStatus)
|
public function testRawRequest()
|
||||||
{
|
{
|
||||||
$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 MessageResponseInterface|MockObject $responseMock */
|
/** @var GuzzleResponse|MockObject $responseMock */
|
||||||
$responseMock = $this->getMockBuilder(MessageResponseInterface::class)
|
$responseMock = $this->getMockBuilder( GuzzleResponse::class)
|
||||||
->onlyMethods([
|
|
||||||
'getStatusCode',
|
|
||||||
'getBody',
|
|
||||||
'withStatus',
|
|
||||||
'getReasonPhrase',
|
|
||||||
'getProtocolVersion',
|
|
||||||
'withProtocolVersion',
|
|
||||||
'getHeaders',
|
|
||||||
'hasHeader',
|
|
||||||
'getHeader',
|
|
||||||
'getHeaderLine',
|
|
||||||
'withHeader',
|
|
||||||
'withAddedHeader',
|
|
||||||
'withoutHeader',
|
|
||||||
'withBody'
|
|
||||||
])
|
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock();
|
||||||
$responseMock->expects($this->atLeastOnce())->method('getStatusCode')->willReturn($statusCode);
|
|
||||||
$responseMock->expects($this->atLeastOnce())
|
$responseMock->expects($this->atLeastOnce())
|
||||||
->method('getBody')->willReturn($streamMock);
|
->method('getBody')->willReturn($streamMock);
|
||||||
|
|
||||||
@ -217,48 +215,21 @@ 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 LoggerHandler|MockObject $loggerHandlerMock */
|
|
||||||
$loggerHandlerMock = $this->getMockBuilder(LoggerHandler::class)
|
|
||||||
->onlyMethods(['getLogger'])
|
|
||||||
->getMock();
|
|
||||||
$loggerHandlerMock->method('getLogger')->willReturn($loggerMock);
|
|
||||||
|
|
||||||
/** @var Client|MockObject $clientMock */
|
/** @var Client|MockObject $clientMock */
|
||||||
$clientMock = $this->getMockBuilder(Client::class)
|
$clientMock = $this->getMockBuilder(Client::class)
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->onlyMethods([
|
->onlyMethods([
|
||||||
'getLoggerHandler'
|
'getLoggerHandler',
|
||||||
])
|
])
|
||||||
->getMock();
|
->getMock();
|
||||||
$clientMock->expects($this->atLeastOnce())
|
|
||||||
->method('getLoggerHandler')->willReturn($loggerHandlerMock);
|
|
||||||
$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 [
|
|
||||||
'OK status' => [true],
|
|
||||||
'NOK status' => [false],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @return void
|
* @return void
|
||||||
@ -275,4 +246,38 @@ class ClientTest extends ApiTestCase
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @return void
|
||||||
|
* @throws \PHPUnit\Framework\ExpectationFailedException
|
||||||
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
|
||||||
|
* @covers \D3\LinkmobilityClient\Client::getLoggerMiddleware
|
||||||
|
*/
|
||||||
|
public function testGetLoggerMiddleware()
|
||||||
|
{
|
||||||
|
$this->assertIsCallable(
|
||||||
|
$this->callMethod(
|
||||||
|
$this->api,
|
||||||
|
'getLoggerMiddleware'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @return void
|
||||||
|
* @throws \PHPUnit\Framework\ExpectationFailedException
|
||||||
|
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
|
||||||
|
* @covers \D3\LinkmobilityClient\Client::getRetryMiddleware
|
||||||
|
*/
|
||||||
|
public function testGetRetryMiddleware()
|
||||||
|
{
|
||||||
|
$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]
|
./vendor/bin/phpunit [--no-coverage] [--coverage-html=cov]
|
||||||
```
|
```
|
||||||
|
@ -167,7 +167,7 @@ class RecipientsListTest extends ApiTestCase
|
|||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
[
|
[
|
||||||
$this->phoneNumberFixture,
|
$this->phoneNumberFixture,
|
||||||
$this->phoneNumberFixture
|
$this->phoneNumberFixture,
|
||||||
],
|
],
|
||||||
$this->callMethod(
|
$this->callMethod(
|
||||||
$this->recipientsList,
|
$this->recipientsList,
|
||||||
@ -280,7 +280,7 @@ class RecipientsListTest extends ApiTestCase
|
|||||||
$this->recipientsList,
|
$this->recipientsList,
|
||||||
'recipients',
|
'recipients',
|
||||||
[
|
[
|
||||||
'fixture' => new stdClass()
|
'fixture' => new stdClass(),
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -333,11 +333,11 @@ class RecipientsListTest extends ApiTestCase
|
|||||||
$recipientMock = $this->getMockBuilder(Recipient::class)
|
$recipientMock = $this->getMockBuilder(Recipient::class)
|
||||||
->onlyMethods([
|
->onlyMethods([
|
||||||
'get',
|
'get',
|
||||||
'getCountryCode'
|
'getCountryCode',
|
||||||
])
|
])
|
||||||
->setConstructorArgs([
|
->setConstructorArgs([
|
||||||
$this->phoneNumberFixture,
|
$this->phoneNumberFixture,
|
||||||
$this->phoneCountryFixture
|
$this->phoneCountryFixture,
|
||||||
])
|
])
|
||||||
->getMock();
|
->getMock();
|
||||||
$recipientMock->method('get')->willReturn($this->phoneNumberFixture);
|
$recipientMock->method('get')->willReturn($this->phoneNumberFixture);
|
||||||
@ -347,11 +347,11 @@ class RecipientsListTest extends ApiTestCase
|
|||||||
$recipientMock2 = $this->getMockBuilder(Recipient::class)
|
$recipientMock2 = $this->getMockBuilder(Recipient::class)
|
||||||
->onlyMethods([
|
->onlyMethods([
|
||||||
'get',
|
'get',
|
||||||
'getCountryCode'
|
'getCountryCode',
|
||||||
])
|
])
|
||||||
->setConstructorArgs([
|
->setConstructorArgs([
|
||||||
$this->phoneNumberFixture,
|
$this->phoneNumberFixture,
|
||||||
$this->phoneCountryFixture
|
$this->phoneCountryFixture,
|
||||||
])
|
])
|
||||||
->getMock();
|
->getMock();
|
||||||
$recipientMock2->method('get')->willReturn($this->phoneNumberFixture);
|
$recipientMock2->method('get')->willReturn($this->phoneNumberFixture);
|
||||||
@ -359,7 +359,7 @@ class RecipientsListTest extends ApiTestCase
|
|||||||
|
|
||||||
$list = [
|
$list = [
|
||||||
'fixture' => $recipientMock,
|
'fixture' => $recipientMock,
|
||||||
'fixture2' => $recipientMock2
|
'fixture2' => $recipientMock2,
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->setValue(
|
$this->setValue(
|
||||||
|
@ -17,6 +17,7 @@ namespace D3\LinkmobilityClient\Tests\Request;
|
|||||||
|
|
||||||
use Assert\InvalidArgumentException;
|
use Assert\InvalidArgumentException;
|
||||||
use D3\LinkmobilityClient\Client;
|
use D3\LinkmobilityClient\Client;
|
||||||
|
use D3\LinkmobilityClient\Exceptions\RecipientException;
|
||||||
use D3\LinkmobilityClient\RecipientsList\RecipientsListInterface;
|
use D3\LinkmobilityClient\RecipientsList\RecipientsListInterface;
|
||||||
use D3\LinkmobilityClient\Request\Request;
|
use D3\LinkmobilityClient\Request\Request;
|
||||||
use D3\LinkmobilityClient\Request\RequestInterface;
|
use D3\LinkmobilityClient\Request\RequestInterface;
|
||||||
@ -24,6 +25,7 @@ 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\PhoneNumberFormat;
|
||||||
use libphonenumber\PhoneNumberType;
|
use libphonenumber\PhoneNumberType;
|
||||||
use libphonenumber\PhoneNumberUtil;
|
use libphonenumber\PhoneNumberUtil;
|
||||||
@ -87,13 +89,10 @@ 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->assertInstanceOf(
|
$this->callMethod(
|
||||||
Request::class,
|
$requestMock,
|
||||||
$this->callMethod(
|
'__construct',
|
||||||
$requestMock,
|
[$messageMock, $clientMock]
|
||||||
'__construct',
|
|
||||||
[$messageMock, $clientMock]
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,10 +114,13 @@ abstract class AbstractRequest extends ApiTestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
|
||||||
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::validate
|
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::validate
|
||||||
* @covers \D3\LinkmobilityClient\SMS\TextRequest::validate
|
* @covers \D3\LinkmobilityClient\SMS\TextRequest::validate
|
||||||
* @covers \D3\LinkmobilityClient\Request\Request::validate
|
* @covers \D3\LinkmobilityClient\Request\Request::validate
|
||||||
|
* @return void
|
||||||
|
* @throws ReflectionException
|
||||||
|
* @throws RecipientException
|
||||||
|
* @throws NumberParseException
|
||||||
*/
|
*/
|
||||||
public function validatePassedTest()
|
public function validatePassedTest()
|
||||||
{
|
{
|
||||||
@ -149,9 +151,12 @@ abstract class AbstractRequest extends ApiTestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
|
||||||
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::validate
|
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::validate
|
||||||
* @covers \D3\LinkmobilityClient\SMS\TextRequest::validate
|
* @covers \D3\LinkmobilityClient\SMS\TextRequest::validate
|
||||||
|
* @return void
|
||||||
|
* @throws NumberParseException
|
||||||
|
* @throws RecipientException
|
||||||
|
* @throws ReflectionException
|
||||||
*/
|
*/
|
||||||
public function validateFailedTest()
|
public function validateFailedTest()
|
||||||
{
|
{
|
||||||
@ -253,17 +258,17 @@ 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,
|
||||||
]
|
],
|
||||||
]
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -284,20 +289,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'
|
||||||
@ -671,7 +676,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('{}');
|
||||||
|
|
||||||
@ -680,12 +685,12 @@ 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],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ abstract class AbstractResponse 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->expects($this->atLeastOnce())->method('getContents')->willReturn(
|
$streamMock->expects($this->atLeastOnce())->method('getContents')->willReturn(
|
||||||
'{
|
'{
|
||||||
@ -53,7 +53,7 @@ abstract class AbstractResponse extends ApiTestCase
|
|||||||
->onlyMethods([
|
->onlyMethods([
|
||||||
'getBody', 'getStatusCode', 'withStatus', 'getReasonphrase', 'getProtocolVersion',
|
'getBody', 'getStatusCode', 'withStatus', 'getReasonphrase', 'getProtocolVersion',
|
||||||
'withProtocolVersion', 'getHeaders', 'hasHeader', 'getHeader', 'getHeaderLine',
|
'withProtocolVersion', 'getHeaders', 'hasHeader', 'getHeader', 'getHeaderLine',
|
||||||
'withHeader', 'withAddedHeader', 'withoutHeader', 'withBody'])
|
'withHeader', 'withAddedHeader', 'withoutHeader', 'withBody', ])
|
||||||
->getMock();
|
->getMock();
|
||||||
$rawResponseMock->method('getBody')->willReturn($streamMock);
|
$rawResponseMock->method('getBody')->willReturn($streamMock);
|
||||||
|
|
||||||
@ -86,7 +86,7 @@ abstract class AbstractResponse extends ApiTestCase
|
|||||||
*/
|
*/
|
||||||
protected function checkProperties($expected, $propertyName, $methodName)
|
protected function checkProperties($expected, $propertyName, $methodName)
|
||||||
{
|
{
|
||||||
/** @var Response $response */
|
/** @var Response|MockObject $responseMock */
|
||||||
$responseMock = $this->getMockBuilder($this->testClassName)
|
$responseMock = $this->getMockBuilder($this->testClassName)
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->onlyMethods(['getContent'])
|
->onlyMethods(['getContent'])
|
||||||
@ -226,7 +226,7 @@ abstract class AbstractResponse extends ApiTestCase
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'successful' => [true, ''],
|
'successful' => [true, ''],
|
||||||
'not successful'=> [false, 'fixtureMessage']
|
'not successful'=> [false, 'fixtureMessage'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,8 +100,8 @@ class RequestFactoryTest extends ApiTestCase
|
|||||||
public function getTextSmsRequestDataProvider(): array
|
public function getTextSmsRequestDataProvider(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'binary' => [RequestFactory::GSM_UCS2, BinaryRequest::class],
|
'binary' => [SmsLength::ENCODING_UCS2, BinaryRequest::class],
|
||||||
'ascii' => [RequestFactory::GSM_7BIT, TextRequest::class]
|
'ascii' => [SmsLength::ENCODING_7BIT, TextRequest::class],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,7 +149,7 @@ class RecipientTest extends ApiTestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string[][]
|
* @return array[]
|
||||||
*/
|
*/
|
||||||
public function constructInvalidDataProvider(): array
|
public function constructInvalidDataProvider(): array
|
||||||
{
|
{
|
||||||
@ -162,7 +162,7 @@ class RecipientTest extends ApiTestCase
|
|||||||
'invalid country code' => [$phoneNumberFixture, 'DEX', true, PhoneNumberType::MOBILE, InvalidArgumentException::class],
|
'invalid country code' => [$phoneNumberFixture, 'DEX', true, PhoneNumberType::MOBILE, InvalidArgumentException::class],
|
||||||
'unparsable' => ['abc', 'DE', true, PhoneNumberType::MOBILE, NumberParseException::class],
|
'unparsable' => ['abc', 'DE', true, PhoneNumberType::MOBILE, NumberParseException::class],
|
||||||
'invalid number' => ['abcd', 'DE', false, PhoneNumberType::MOBILE, RecipientException::class],
|
'invalid number' => ['abcd', 'DE', false, PhoneNumberType::MOBILE, RecipientException::class],
|
||||||
'not mobile number' => ['abcd', 'DE', true, PhoneNumberType::FIXED_LINE, RecipientException::class]
|
'not mobile number' => ['abcd', 'DE', true, PhoneNumberType::FIXED_LINE, RecipientException::class],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,6 @@ declare(strict_types=1);
|
|||||||
namespace D3\LinkmobilityClient\Tests\ValueObject;
|
namespace D3\LinkmobilityClient\Tests\ValueObject;
|
||||||
|
|
||||||
use Assert\InvalidArgumentException;
|
use Assert\InvalidArgumentException;
|
||||||
use D3\LinkmobilityClient\Exceptions\NoSenderDefinedException;
|
|
||||||
use D3\LinkmobilityClient\Exceptions\RecipientException;
|
use D3\LinkmobilityClient\Exceptions\RecipientException;
|
||||||
use D3\LinkmobilityClient\Tests\ApiTestCase;
|
use D3\LinkmobilityClient\Tests\ApiTestCase;
|
||||||
use D3\LinkmobilityClient\ValueObject\Sender;
|
use D3\LinkmobilityClient\ValueObject\Sender;
|
||||||
@ -30,7 +29,7 @@ use ReflectionException;
|
|||||||
|
|
||||||
class SenderTest extends ApiTestCase
|
class SenderTest extends ApiTestCase
|
||||||
{
|
{
|
||||||
/** @var Sender */
|
/** @var Sender|MockObject */
|
||||||
public $sender;
|
public $sender;
|
||||||
|
|
||||||
private $phoneNumberFixture;
|
private $phoneNumberFixture;
|
||||||
@ -49,7 +48,6 @@ class SenderTest extends ApiTestCase
|
|||||||
$example = $phoneUtil->getExampleNumberForType($this->phoneCountryFixture, PhoneNumberType::MOBILE);
|
$example = $phoneUtil->getExampleNumberForType($this->phoneCountryFixture, PhoneNumberType::MOBILE);
|
||||||
$this->phoneNumberFixture = $phoneUtil->format($example, PhoneNumberFormat::NATIONAL);
|
$this->phoneNumberFixture = $phoneUtil->format($example, PhoneNumberFormat::NATIONAL);
|
||||||
|
|
||||||
/** @var Sender|MockObject sender */
|
|
||||||
$this->sender = new Sender($this->phoneNumberFixture, $this->phoneCountryFixture);
|
$this->sender = new Sender($this->phoneNumberFixture, $this->phoneCountryFixture);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,7 +110,7 @@ class SenderTest extends ApiTestCase
|
|||||||
return [
|
return [
|
||||||
'null number' => [null, $this->phoneCountryFixture, false],
|
'null number' => [null, $this->phoneCountryFixture, false],
|
||||||
'null country' => [$this->phoneNumberFixture, null, false],
|
'null country' => [$this->phoneNumberFixture, null, false],
|
||||||
'all values' => [$this->phoneNumberFixture, $this->phoneCountryFixture, true]
|
'all values' => [$this->phoneNumberFixture, $this->phoneCountryFixture, true],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,11 +120,9 @@ class SenderTest extends ApiTestCase
|
|||||||
* @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
|
* @covers \D3\LinkmobilityClient\ValueObject\Sender::__construct
|
||||||
*/
|
*/
|
||||||
public function testConstructInvalid($number, $country, $validNumber, $expectedException)
|
public function testConstructInvalid($number, $country, $validNumber, $expectedException)
|
||||||
{
|
{
|
||||||
@ -162,7 +158,7 @@ class SenderTest extends ApiTestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string[][]
|
* @return array[]
|
||||||
*/
|
*/
|
||||||
public function constructInvalidDataProvider(): array
|
public function constructInvalidDataProvider(): array
|
||||||
{
|
{
|
||||||
@ -174,7 +170,7 @@ class SenderTest extends ApiTestCase
|
|||||||
'empty number' => ['', 'DE', true, InvalidArgumentException::class],
|
'empty number' => ['', 'DE', true, InvalidArgumentException::class],
|
||||||
'invalid country code' => [$phoneNumberFixture, 'DEX', true, InvalidArgumentException::class],
|
'invalid country code' => [$phoneNumberFixture, 'DEX', true, InvalidArgumentException::class],
|
||||||
'unparsable' => ['abc', 'DE', true, NumberParseException::class],
|
'unparsable' => ['abc', 'DE', true, NumberParseException::class],
|
||||||
'invalid number' => ['abcd', 'DE', false, RecipientException::class]
|
'invalid number' => ['abcd', 'DE', false, RecipientException::class],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,14 +15,13 @@ 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 ApiTestCase
|
class SmsBinaryMessageTest extends SmsMessageAbstractTest
|
||||||
{
|
{
|
||||||
/** @var SmsBinaryMessage */
|
/** @var SmsBinaryMessage */
|
||||||
public $message;
|
public $message;
|
||||||
@ -39,21 +38,12 @@ class SmsBinaryMessageTest extends ApiTestCase
|
|||||||
$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\SmsBinaryMessage::__construct
|
||||||
|
* @covers \D3\LinkmobilityClient\ValueObject\SmsMessageAbstract::__construct
|
||||||
*/
|
*/
|
||||||
public function testConstructValid()
|
public function testConstructValid()
|
||||||
{
|
{
|
||||||
@ -91,6 +81,7 @@ class SmsBinaryMessageTest extends ApiTestCase
|
|||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
* @dataProvider constructInvalidDataProvider
|
* @dataProvider constructInvalidDataProvider
|
||||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsBinaryMessage::__construct
|
* @covers \D3\LinkmobilityClient\ValueObject\SmsBinaryMessage::__construct
|
||||||
|
* @covers \D3\LinkmobilityClient\ValueObject\SmsMessageAbstract::__construct
|
||||||
*/
|
*/
|
||||||
public function testConstructInvalid($binaryMessage, $valid, $expectedException)
|
public function testConstructInvalid($binaryMessage, $valid, $expectedException)
|
||||||
{
|
{
|
||||||
@ -102,7 +93,7 @@ class SmsBinaryMessageTest extends ApiTestCase
|
|||||||
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 \Phlib\SmsLength\Exception\InvalidArgumentException());
|
$smsLengthMock->expects($this->atLeastOnce())->method('validate')->willThrowException(new InvalidArgumentException());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var SmsBinaryMessage|MockObject $message */
|
/** @var SmsBinaryMessage|MockObject $message */
|
||||||
@ -124,37 +115,11 @@ class SmsBinaryMessageTest extends ApiTestCase
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string[][]
|
|
||||||
*/
|
|
||||||
public function constructInvalidDataProvider(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'empty message' => ['', true, InvalidArgumentException::class],
|
|
||||||
'invalid sms message' => ['abc', false, \Phlib\SmsLength\Exception\InvalidArgumentException::class]
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @test
|
|
||||||
* @throws ReflectionException
|
|
||||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsBinaryMessage::getSmsLength
|
|
||||||
*/
|
|
||||||
public function testGetSmsLengthInstance()
|
|
||||||
{
|
|
||||||
$this->assertInstanceOf(
|
|
||||||
SmsLength::class,
|
|
||||||
$this->callMethod(
|
|
||||||
$this->message,
|
|
||||||
'getSmsLength'
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsBinaryMessage::chunkCount
|
* @covers \D3\LinkmobilityClient\ValueObject\SmsBinaryMessage::chunkCount
|
||||||
|
* @covers \D3\LinkmobilityClient\ValueObject\SmsMessageAbstract::chunkCount
|
||||||
*/
|
*/
|
||||||
public function testGetChunkCount()
|
public function testGetChunkCount()
|
||||||
{
|
{
|
||||||
@ -170,9 +135,9 @@ class SmsBinaryMessageTest extends ApiTestCase
|
|||||||
|
|
||||||
/** @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(
|
||||||
@ -188,6 +153,7 @@ class SmsBinaryMessageTest extends ApiTestCase
|
|||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsBinaryMessage::length
|
* @covers \D3\LinkmobilityClient\ValueObject\SmsBinaryMessage::length
|
||||||
|
* @covers \D3\LinkmobilityClient\ValueObject\SmsMessageAbstract::length
|
||||||
*/
|
*/
|
||||||
public function testGetSize()
|
public function testGetSize()
|
||||||
{
|
{
|
||||||
|
65
Tests/ValueObject/SmsMessageAbstractTest.php
Normal file
65
Tests/ValueObject/SmsMessageAbstractTest.php
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
<?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 SmsBinaryMessageTest
|
class SmsTextMessageTest extends SmsMessageAbstractTest
|
||||||
{
|
{
|
||||||
/** @var SmsTextMessage */
|
/** @var SmsTextMessage */
|
||||||
public $message;
|
public $message;
|
||||||
@ -43,6 +43,7 @@ class SmsTextMessageTest extends SmsBinaryMessageTest
|
|||||||
* @return void
|
* @return void
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsTextMessage::__construct
|
* @covers \D3\LinkmobilityClient\ValueObject\SmsTextMessage::__construct
|
||||||
|
* @covers \D3\LinkmobilityClient\ValueObject\SmsMessageAbstract::__construct
|
||||||
*/
|
*/
|
||||||
public function testConstructValid()
|
public function testConstructValid()
|
||||||
{
|
{
|
||||||
@ -80,6 +81,7 @@ class SmsTextMessageTest extends SmsBinaryMessageTest
|
|||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
* @dataProvider constructInvalidDataProvider
|
* @dataProvider constructInvalidDataProvider
|
||||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsTextMessage::__construct
|
* @covers \D3\LinkmobilityClient\ValueObject\SmsTextMessage::__construct
|
||||||
|
* @covers \D3\LinkmobilityClient\ValueObject\SmsMessageAbstract::__construct
|
||||||
*/
|
*/
|
||||||
public function testConstructInvalid($binaryMessage, $valid, $expectedException)
|
public function testConstructInvalid($binaryMessage, $valid, $expectedException)
|
||||||
{
|
{
|
||||||
@ -112,4 +114,104 @@ class SmsTextMessageTest extends SmsBinaryMessageTest
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\ValueObject\SmsTextMessage::chunkCount
|
||||||
|
* @covers \D3\LinkmobilityClient\ValueObject\SmsMessageAbstract::chunkCount
|
||||||
|
*/
|
||||||
|
public function testGetChunkCount()
|
||||||
|
{
|
||||||
|
$expected = 2;
|
||||||
|
|
||||||
|
/** @var SmsLength|MockObject $smsLengthMock */
|
||||||
|
$smsLengthMock = $this->getMockBuilder(SmsLength::class)
|
||||||
|
->onlyMethods(['getMessageCount', 'validate'])
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->getMock();
|
||||||
|
$smsLengthMock->expects($this->once())->method('getMessageCount')->willReturn($expected);
|
||||||
|
$smsLengthMock->method('validate')->willReturn(true);
|
||||||
|
|
||||||
|
/** @var SmsTextMessage|MockObject $message */
|
||||||
|
$message = $this->getMockBuilder(SmsTextMessage::class)
|
||||||
|
->onlyMethods(['getSmsLength'])
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->getMock();
|
||||||
|
$message->method('getSmsLength')->willReturn($smsLengthMock);
|
||||||
|
|
||||||
|
$this->assertSame(
|
||||||
|
$expected,
|
||||||
|
$this->callMethod(
|
||||||
|
$message,
|
||||||
|
'chunkCount'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\ValueObject\SmsTextMessage::length
|
||||||
|
* @covers \D3\LinkmobilityClient\ValueObject\SmsMessageAbstract::length
|
||||||
|
*/
|
||||||
|
public function testGetSize()
|
||||||
|
{
|
||||||
|
$expected = 55;
|
||||||
|
|
||||||
|
/** @var SmsLength|MockObject $smsLengthMock */
|
||||||
|
$smsLengthMock = $this->getMockBuilder(SmsLength::class)
|
||||||
|
->onlyMethods(['getSize', 'validate'])
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->getMock();
|
||||||
|
$smsLengthMock->expects($this->once())->method('getSize')->willReturn($expected);
|
||||||
|
$smsLengthMock->method('validate')->willReturn(true);
|
||||||
|
|
||||||
|
/** @var SmsTextMessage|MockObject $message */
|
||||||
|
$message = $this->getMockBuilder(SmsTextMessage::class)
|
||||||
|
->onlyMethods(['getSmsLength'])
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->getMock();
|
||||||
|
$message->method('getSmsLength')->willReturn($smsLengthMock);
|
||||||
|
|
||||||
|
$this->assertSame(
|
||||||
|
$expected,
|
||||||
|
$this->callMethod(
|
||||||
|
$message,
|
||||||
|
'length'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @throws ReflectionException
|
||||||
|
* @covers \D3\LinkmobilityClient\ValueObject\SmsTextMessage::getMessageContent
|
||||||
|
* @covers \D3\LinkmobilityClient\ValueObject\SmsMessageAbstract::getMessageContent
|
||||||
|
*/
|
||||||
|
public function testGetMessageContent()
|
||||||
|
{
|
||||||
|
/** @var SmsLength|MockObject $smsLengthMock */
|
||||||
|
$smsLengthMock = $this->getMockBuilder(SmsLength::class)
|
||||||
|
->onlyMethods(['validate'])
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->getMock();
|
||||||
|
$smsLengthMock->method('validate')->willReturn(true);
|
||||||
|
|
||||||
|
/** @var SmsTextMessage|MockObject $message */
|
||||||
|
$message = $this->getMockBuilder(SmsTextMessage::class)
|
||||||
|
->onlyMethods(['getSmsLength'])
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->getMock();
|
||||||
|
$message->method('getSmsLength')->willReturn($smsLengthMock);
|
||||||
|
$message->__construct($this->messageFixture);
|
||||||
|
|
||||||
|
$this->assertSame(
|
||||||
|
'testMessage',
|
||||||
|
$this->callMethod(
|
||||||
|
$message,
|
||||||
|
'getMessageContent'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,13 +16,8 @@ declare(strict_types=1);
|
|||||||
namespace D3\LinkmobilityClient\Tests\ValueObject;
|
namespace D3\LinkmobilityClient\Tests\ValueObject;
|
||||||
|
|
||||||
use Assert\InvalidArgumentException;
|
use Assert\InvalidArgumentException;
|
||||||
use D3\LinkmobilityClient\Exceptions\NoSenderDefinedException;
|
|
||||||
use D3\LinkmobilityClient\Exceptions\RecipientException;
|
|
||||||
use D3\LinkmobilityClient\Tests\ApiTestCase;
|
use D3\LinkmobilityClient\Tests\ApiTestCase;
|
||||||
use D3\LinkmobilityClient\ValueObject\Sender;
|
|
||||||
use D3\LinkmobilityClient\ValueObject\ValueObject;
|
use D3\LinkmobilityClient\ValueObject\ValueObject;
|
||||||
use libphonenumber\NumberParseException;
|
|
||||||
use libphonenumber\PhoneNumber;
|
|
||||||
use libphonenumber\PhoneNumberFormat;
|
use libphonenumber\PhoneNumberFormat;
|
||||||
use libphonenumber\PhoneNumberType;
|
use libphonenumber\PhoneNumberType;
|
||||||
use libphonenumber\PhoneNumberUtil;
|
use libphonenumber\PhoneNumberUtil;
|
||||||
@ -31,11 +26,13 @@ use ReflectionException;
|
|||||||
|
|
||||||
class ValueObjectTest extends ApiTestCase
|
class ValueObjectTest extends ApiTestCase
|
||||||
{
|
{
|
||||||
|
/** @var ValueObject|MockObject */
|
||||||
|
public $value;
|
||||||
|
|
||||||
public function setUp(): void
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
/** @var ValueObject|MockObject value */
|
|
||||||
$this->value = $this->getMockBuilder(ValueObject::class)
|
$this->value = $this->getMockBuilder(ValueObject::class)
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock();
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "d3/linkmobility-php-client",
|
"name": "d3/linkmobility-php-client",
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"description": "PHP client for LINK Mobility Austria API",
|
"description": "PHP client for LINK Mobility API",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"LINK Mobility",
|
"LINK Mobility",
|
||||||
"php",
|
"php",
|
||||||
@ -21,18 +21,20 @@
|
|||||||
"GPL-3.0-or-later"
|
"GPL-3.0-or-later"
|
||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^7.0 || ^8.0",
|
"php": "^7.3 || ^8.0.3",
|
||||||
"beberlei/assert": "^2.9.9",
|
"beberlei/assert": "^3.3",
|
||||||
"guzzlehttp/guzzle": "~6.2 || ^7.4",
|
"guzzlehttp/guzzle": "^7.3",
|
||||||
"psr/http-message": "~1.0",
|
"psr/http-message": "^1.0 || ^2.0",
|
||||||
"phlib/sms-length": "^1.1.0 || ^2.0.0",
|
"phlib/sms-length": "^2.0",
|
||||||
"giggsey/libphonenumber-for-php": "^8.12.50",
|
"giggsey/libphonenumber-for-php": "^8.12.50",
|
||||||
|
"caseyamcl/guzzle_retry_middleware": "^2.8",
|
||||||
"ext-json": "*"
|
"ext-json": "*"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"php": "^7.2",
|
"php": "^7.4 || ~8.0.3",
|
||||||
"phpunit/phpunit" : "^8.0",
|
"phpunit/phpunit" : "^9.5",
|
||||||
"friendsofphp/php-cs-fixer": "^2.0"
|
"friendsofphp/php-cs-fixer": "^3.9",
|
||||||
|
"phpstan/phpstan": "^1.8"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
@ -41,8 +43,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "phpunit",
|
"test": "./vendor/bin/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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
6
phpstan.neon
Normal file
6
phpstan.neon
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
parameters:
|
||||||
|
paths:
|
||||||
|
- src
|
||||||
|
- Tests
|
||||||
|
level: 5
|
||||||
|
phpVersion: 70300
|
40
phpunit.xml
40
phpunit.xml
@ -1,22 +1,20 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
<phpunit
|
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
bootstrap="vendor/autoload.php"
|
bootstrap="vendor/autoload.php"
|
||||||
convertErrorsToExceptions="true"
|
convertErrorsToExceptions="true"
|
||||||
convertNoticesToExceptions="true"
|
convertNoticesToExceptions="true"
|
||||||
convertWarningsToExceptions="true">
|
convertWarningsToExceptions="true"
|
||||||
|
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
|
||||||
<testsuite name="linkmobility">
|
<coverage>
|
||||||
<directory>./Tests</directory>
|
<include>
|
||||||
</testsuite>
|
<directory suffix=".php">src</directory>
|
||||||
|
</include>
|
||||||
<filter>
|
<report>
|
||||||
<whitelist>
|
<clover outputFile="build/logs/clover.xml"/>
|
||||||
<directory suffix=".php">src</directory>
|
</report>
|
||||||
</whitelist>
|
</coverage>
|
||||||
</filter>
|
<testsuite name="linkmobility">
|
||||||
|
<directory>./Tests</directory>
|
||||||
<logging>
|
</testsuite>
|
||||||
<log type="coverage-clover" target="build/logs/clover.xml"/>
|
<logging/>
|
||||||
</logging>
|
|
||||||
|
|
||||||
</phpunit>
|
</phpunit>
|
||||||
|
@ -15,14 +15,17 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace D3\LinkmobilityClient;
|
namespace D3\LinkmobilityClient;
|
||||||
|
|
||||||
use D3\LinkmobilityClient\Exceptions\ApiException;
|
use Assert\InvalidArgumentException;
|
||||||
use D3\LinkmobilityClient\Exceptions\ExceptionMessages;
|
|
||||||
use D3\LinkmobilityClient\Request\RequestInterface;
|
use D3\LinkmobilityClient\Request\RequestInterface;
|
||||||
use D3\LinkmobilityClient\Url\Url;
|
use D3\LinkmobilityClient\Url\Url;
|
||||||
use D3\LinkmobilityClient\Url\UrlInterface;
|
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 InvalidArgumentException;
|
use GuzzleHttp\HandlerStack;
|
||||||
|
use GuzzleHttp\MessageFormatter;
|
||||||
|
use GuzzleHttp\Middleware;
|
||||||
|
use GuzzleRetry\GuzzleRetryMiddleware;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
|
||||||
class Client
|
class Client
|
||||||
@ -35,14 +38,28 @@ class Client
|
|||||||
{
|
{
|
||||||
$this->accessToken = $accessToken;
|
$this->accessToken = $accessToken;
|
||||||
$this->apiUrl = $apiUrl ?: new Url();
|
$this->apiUrl = $apiUrl ?: new Url();
|
||||||
$this->requestClient = $client ?: new \GuzzleHttp\Client([ 'base_uri' => $this->apiUrl->getBaseUri() ]);
|
$this->requestClient = $client ?: $this->getDefaultClient();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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
|
||||||
*/
|
*/
|
||||||
@ -61,30 +78,14 @@ 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;
|
||||||
|
|
||||||
$this->getLoggerHandler()->getLogger()->debug('linkmobility request: '.$url, $options);
|
$response = $this->requestClient->request($method, $url, $options);
|
||||||
|
|
||||||
$response = $this->requestClient->request(
|
|
||||||
$method,
|
|
||||||
$url,
|
|
||||||
$options
|
|
||||||
);
|
|
||||||
|
|
||||||
if ($response->getStatusCode() != 200) {
|
|
||||||
$message = sprintf(ExceptionMessages::NOK_REQUEST_RETURN, $url, $response->getStatusCode());
|
|
||||||
$response->getBody()->rewind();
|
|
||||||
$this->getLoggerHandler()->getLogger()->error($message, [$response->getBody()->getContents()]);
|
|
||||||
throw new ApiException($message);
|
|
||||||
}
|
|
||||||
|
|
||||||
$response->getBody()->rewind();
|
$response->getBody()->rewind();
|
||||||
$this->getLoggerHandler()->getLogger()->debug('response', [$response->getBody()->getContents()]);
|
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
@ -96,4 +97,28 @@ class Client
|
|||||||
{
|
{
|
||||||
return LoggerHandler::getInstance();
|
return LoggerHandler::getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $loglevel
|
||||||
|
*
|
||||||
|
* @return callable
|
||||||
|
*/
|
||||||
|
protected function getLoggerMiddleware(string $loglevel = 'debug'): callable
|
||||||
|
{
|
||||||
|
return Middleware::log(
|
||||||
|
$this->getLoggerHandler()->getLogger(),
|
||||||
|
new MessageFormatter(MessageFormatter::DEBUG),
|
||||||
|
$loglevel
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return callable
|
||||||
|
*/
|
||||||
|
protected function getRetryMiddleware(): callable
|
||||||
|
{
|
||||||
|
return GuzzleRetryMiddleware::factory([
|
||||||
|
'max_retry_attempts' => 3
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,20 +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\Exceptions;
|
|
||||||
|
|
||||||
class ApiException extends LinkmobilityException
|
|
||||||
{
|
|
||||||
}
|
|
@ -42,7 +42,7 @@ class LoggerHandler
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mixed $logger
|
* @param LoggerInterface $logger
|
||||||
*/
|
*/
|
||||||
public function setLogger(LoggerInterface $logger)
|
public function setLogger(LoggerInterface $logger)
|
||||||
{
|
{
|
||||||
|
@ -31,9 +31,15 @@ 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)
|
||||||
{
|
{
|
||||||
$this->setClient($client);
|
if ($client) {
|
||||||
|
$this->setClient( $client );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -113,6 +119,7 @@ class RecipientsList implements RecipientsListInterface, Iterator
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @deprecated
|
||||||
* @return Client
|
* @return Client
|
||||||
*/
|
*/
|
||||||
public function getClient(): Client
|
public function getClient(): Client
|
||||||
@ -121,6 +128,7 @@ class RecipientsList implements RecipientsListInterface, Iterator
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @deprecated
|
||||||
* @param Client $client
|
* @param Client $client
|
||||||
*
|
*
|
||||||
* @return RecipientsList
|
* @return RecipientsList
|
||||||
|
@ -20,6 +20,10 @@ 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;
|
||||||
@ -27,4 +31,6 @@ interface RecipientsListInterface
|
|||||||
public function clearRecipents(): RecipientsListInterface;
|
public function clearRecipents(): RecipientsListInterface;
|
||||||
|
|
||||||
public function getRecipients(): array;
|
public function getRecipients(): array;
|
||||||
|
|
||||||
|
public function getRecipientsList(): array;
|
||||||
}
|
}
|
||||||
|
@ -16,6 +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\Exceptions\ExceptionMessages;
|
||||||
use D3\LinkmobilityClient\RecipientsList\RecipientsList;
|
use D3\LinkmobilityClient\RecipientsList\RecipientsList;
|
||||||
@ -25,9 +26,7 @@ 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
|
||||||
{
|
{
|
||||||
@ -107,7 +106,7 @@ abstract class Request implements RequestInterface
|
|||||||
private $test = false;
|
private $test = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var bool
|
* @var int
|
||||||
*/
|
*/
|
||||||
private $maxSmsPerMessage = 0;
|
private $maxSmsPerMessage = 0;
|
||||||
|
|
||||||
@ -119,8 +118,6 @@ 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -169,7 +166,7 @@ abstract class Request implements RequestInterface
|
|||||||
'senderAddress' => $this->getSenderAddress() ? $this->getSenderAddress()->getFormatted() : null,
|
'senderAddress' => $this->getSenderAddress() ? $this->getSenderAddress()->getFormatted() : null,
|
||||||
'senderAddressType' => $this->getSenderAddressType(),
|
'senderAddressType' => $this->getSenderAddressType(),
|
||||||
'test' => $this->getTestMode(),
|
'test' => $this->getTestMode(),
|
||||||
'validityPeriode' => $this->getValidityPeriode()
|
'validityPeriode' => $this->getValidityPeriode(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,18 +197,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 StringValueObject $message
|
* @param SmsMessageInterface $message
|
||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function setMessage(StringValueObject $message): Request
|
public function setMessage(SmsMessageInterface $message): Request
|
||||||
{
|
{
|
||||||
$this->message = $message;
|
$this->message = $message;
|
||||||
|
|
||||||
@ -280,7 +277,7 @@ abstract class Request implements RequestInterface
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getClientMessageId()
|
public function getClientMessageId(): ?string
|
||||||
{
|
{
|
||||||
return $this->clientMessageId;
|
return $this->clientMessageId;
|
||||||
}
|
}
|
||||||
@ -306,7 +303,7 @@ abstract class Request implements RequestInterface
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
RequestInterface::CONTENTCATEGORY_ADVERTISEMENT => RequestInterface::CONTENTCATEGORY_ADVERTISEMENT,
|
RequestInterface::CONTENTCATEGORY_ADVERTISEMENT => RequestInterface::CONTENTCATEGORY_ADVERTISEMENT,
|
||||||
RequestInterface::CONTENTCATEGORY_INFORMATIONAL => RequestInterface::CONTENTCATEGORY_INFORMATIONAL
|
RequestInterface::CONTENTCATEGORY_INFORMATIONAL => RequestInterface::CONTENTCATEGORY_INFORMATIONAL,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -376,7 +373,7 @@ abstract class Request implements RequestInterface
|
|||||||
/**
|
/**
|
||||||
* @return string|null
|
* @return string|null
|
||||||
*/
|
*/
|
||||||
public function getNotificationCallbackUrl()
|
public function getNotificationCallbackUrl(): ?string
|
||||||
{
|
{
|
||||||
return $this->notificationCallbackUrl;
|
return $this->notificationCallbackUrl;
|
||||||
}
|
}
|
||||||
@ -396,7 +393,7 @@ abstract class Request implements RequestInterface
|
|||||||
/**
|
/**
|
||||||
* @return int|null
|
* @return int|null
|
||||||
*/
|
*/
|
||||||
public function getPriority()
|
public function getPriority(): ?int
|
||||||
{
|
{
|
||||||
return $this->priority;
|
return $this->priority;
|
||||||
}
|
}
|
||||||
@ -422,7 +419,7 @@ abstract class Request implements RequestInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool|null
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function doSendAsFlashSms(): bool
|
public function doSendAsFlashSms(): bool
|
||||||
{
|
{
|
||||||
@ -444,7 +441,7 @@ abstract class Request implements RequestInterface
|
|||||||
/**
|
/**
|
||||||
* @return Sender|null
|
* @return Sender|null
|
||||||
*/
|
*/
|
||||||
public function getSenderAddress()
|
public function getSenderAddress(): ?Sender
|
||||||
{
|
{
|
||||||
return $this->senderAddress;
|
return $this->senderAddress;
|
||||||
}
|
}
|
||||||
@ -464,7 +461,7 @@ abstract class Request implements RequestInterface
|
|||||||
/**
|
/**
|
||||||
* @return string|null
|
* @return string|null
|
||||||
*/
|
*/
|
||||||
public function getSenderAddressType()
|
public function getSenderAddressType(): ?string
|
||||||
{
|
{
|
||||||
return $this->getSenderAddress() && $this->getSenderAddress()->get() ? $this->senderAddressType : null;
|
return $this->getSenderAddress() && $this->getSenderAddress()->get() ? $this->senderAddressType : null;
|
||||||
}
|
}
|
||||||
@ -478,7 +475,7 @@ abstract class Request implements RequestInterface
|
|||||||
RequestInterface::SENDERADDRESSTYPE_ALPHANUMERIC => RequestInterface::SENDERADDRESSTYPE_ALPHANUMERIC,
|
RequestInterface::SENDERADDRESSTYPE_ALPHANUMERIC => RequestInterface::SENDERADDRESSTYPE_ALPHANUMERIC,
|
||||||
RequestInterface::SENDERADDRESSTYPE_INTERNATIONAL => RequestInterface::SENDERADDRESSTYPE_INTERNATIONAL,
|
RequestInterface::SENDERADDRESSTYPE_INTERNATIONAL => RequestInterface::SENDERADDRESSTYPE_INTERNATIONAL,
|
||||||
RequestInterface::SENDERADDRESSTYPE_NATIONAL => RequestInterface::SENDERADDRESSTYPE_NATIONAL,
|
RequestInterface::SENDERADDRESSTYPE_NATIONAL => RequestInterface::SENDERADDRESSTYPE_NATIONAL,
|
||||||
RequestInterface::SENDERADDRESSTYPE_SHORTCODE => RequestInterface::SENDERADDRESSTYPE_SHORTCODE
|
RequestInterface::SENDERADDRESSTYPE_SHORTCODE => RequestInterface::SENDERADDRESSTYPE_SHORTCODE,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -497,7 +494,7 @@ abstract class Request implements RequestInterface
|
|||||||
/**
|
/**
|
||||||
* @return int|null
|
* @return int|null
|
||||||
*/
|
*/
|
||||||
public function getValidityPeriode()
|
public function getValidityPeriode(): ?int
|
||||||
{
|
{
|
||||||
return $this->validityPeriode;
|
return $this->validityPeriode;
|
||||||
}
|
}
|
||||||
@ -523,6 +520,7 @@ abstract class Request implements RequestInterface
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Client $client
|
* @param Client $client
|
||||||
|
* @return Request
|
||||||
*/
|
*/
|
||||||
public function setClient(Client $client): Request
|
public function setClient(Client $client): Request
|
||||||
{
|
{
|
||||||
|
@ -15,15 +15,16 @@ 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\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';
|
||||||
@ -42,6 +43,7 @@ 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 SmsMessageInterface $message
|
||||||
|
@ -72,7 +72,7 @@ abstract class Response implements ResponseInterface
|
|||||||
/**
|
/**
|
||||||
* @return string|null
|
* @return string|null
|
||||||
*/
|
*/
|
||||||
public function getClientMessageId()
|
public function getClientMessageId(): ?string
|
||||||
{
|
{
|
||||||
return $this->getContent()[self::CLIENTMESSAGEID];
|
return $this->getContent()[self::CLIENTMESSAGEID];
|
||||||
}
|
}
|
||||||
@ -80,13 +80,13 @@ abstract class Response implements ResponseInterface
|
|||||||
/**
|
/**
|
||||||
* @return string|null
|
* @return string|null
|
||||||
*/
|
*/
|
||||||
public function getTransferId()
|
public function getTransferId(): ?string
|
||||||
{
|
{
|
||||||
return $this->getContent()[self::TRANSFERID];
|
return $this->getContent()[self::TRANSFERID];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string|null
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function getSmsCount(): int
|
public function getSmsCount(): int
|
||||||
{
|
{
|
||||||
|
@ -16,10 +16,10 @@ 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\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
|
||||||
{
|
{
|
||||||
@ -36,7 +36,7 @@ class BinaryRequest extends Request implements SmsRequestInterface
|
|||||||
return array_merge(
|
return array_merge(
|
||||||
parent::getRawBody(),
|
parent::getRawBody(),
|
||||||
[
|
[
|
||||||
'userDataHeaderPresent' => true
|
'userDataHeaderPresent' => true,
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -20,21 +20,15 @@ use D3\LinkmobilityClient\ValueObject\SmsBinaryMessage;
|
|||||||
use D3\LinkmobilityClient\ValueObject\SmsTextMessage;
|
use D3\LinkmobilityClient\ValueObject\SmsTextMessage;
|
||||||
use Phlib\SmsLength\SmsLength;
|
use Phlib\SmsLength\SmsLength;
|
||||||
|
|
||||||
class RequestFactory
|
class RequestFactory implements RequestFactoryInterface
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @deprecated is SmsLength constant from version 2.1
|
|
||||||
*/
|
|
||||||
public const GSM_7BIT = '7-bit';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated is SmsLength constant from version 2.1
|
|
||||||
*/
|
|
||||||
public const GSM_UCS2 = 'ucs-2';
|
|
||||||
|
|
||||||
protected $message;
|
protected $message;
|
||||||
protected $client;
|
protected $client;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $message
|
||||||
|
* @param Client $client
|
||||||
|
*/
|
||||||
public function __construct($message, Client $client)
|
public function __construct($message, Client $client)
|
||||||
{
|
{
|
||||||
$this->message = $message;
|
$this->message = $message;
|
||||||
@ -46,7 +40,7 @@ class RequestFactory
|
|||||||
*/
|
*/
|
||||||
public function getSmsRequest(): SmsRequestInterface
|
public function getSmsRequest(): SmsRequestInterface
|
||||||
{
|
{
|
||||||
if ($this->getSmsLength()->getEncoding() === self::GSM_7BIT) {
|
if ($this->getSmsLength()->getEncoding() === SmsLength::ENCODING_7BIT) {
|
||||||
$message = new SmsTextMessage($this->message);
|
$message = new SmsTextMessage($this->message);
|
||||||
return new TextRequest($message, $this->client);
|
return new TextRequest($message, $this->client);
|
||||||
}
|
}
|
||||||
|
@ -15,9 +15,11 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace D3\LinkmobilityClient\SMS;
|
namespace D3\LinkmobilityClient\SMS;
|
||||||
|
|
||||||
|
use D3\LinkmobilityClient\Client;
|
||||||
|
|
||||||
interface RequestFactoryInterface
|
interface RequestFactoryInterface
|
||||||
{
|
{
|
||||||
public function __construct($message);
|
public function __construct($message, Client $client);
|
||||||
|
|
||||||
public function getRequest(): SmsRequestInterface;
|
public function getSmsRequest(): SmsRequestInterface;
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,8 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace D3\LinkmobilityClient\SMS;
|
namespace D3\LinkmobilityClient\SMS;
|
||||||
|
|
||||||
class Response extends \D3\LinkmobilityClient\Response\Response
|
use D3\LinkmobilityClient\Response\Response as BaseResponse;
|
||||||
|
|
||||||
|
class Response extends BaseResponse
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -16,10 +16,10 @@ 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\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
|
||||||
{
|
{
|
||||||
|
@ -30,7 +30,7 @@ class Url implements UrlInterface
|
|||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getTextSmsUri()
|
public function getTextSmsUri(): string
|
||||||
{
|
{
|
||||||
return '/rest/smsmessaging/text';
|
return '/rest/smsmessaging/text';
|
||||||
}
|
}
|
||||||
@ -38,7 +38,7 @@ class Url implements UrlInterface
|
|||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getBinarySmsUri()
|
public function getBinarySmsUri(): string
|
||||||
{
|
{
|
||||||
return '/rest/smsmessaging/binary';
|
return '/rest/smsmessaging/binary';
|
||||||
}
|
}
|
||||||
|
@ -18,4 +18,8 @@ namespace D3\LinkmobilityClient\Url;
|
|||||||
interface UrlInterface
|
interface UrlInterface
|
||||||
{
|
{
|
||||||
public function getBaseUri(): string;
|
public function getBaseUri(): string;
|
||||||
|
|
||||||
|
public function getTextSmsUri(): string;
|
||||||
|
|
||||||
|
public function getBinarySmsUri(): string;
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ 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\RecipientException;
|
use D3\LinkmobilityClient\Exceptions\RecipientException;
|
||||||
use libphonenumber\NumberParseException;
|
use libphonenumber\NumberParseException;
|
||||||
@ -30,7 +31,7 @@ class Recipient extends StringValueObject
|
|||||||
*/
|
*/
|
||||||
protected $allowedNumberTypes = [
|
protected $allowedNumberTypes = [
|
||||||
PhoneNumberType::MOBILE,
|
PhoneNumberType::MOBILE,
|
||||||
PhoneNumberType::FIXED_LINE_OR_MOBILE
|
PhoneNumberType::FIXED_LINE_OR_MOBILE,
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -44,6 +45,7 @@ class Recipient extends StringValueObject
|
|||||||
*
|
*
|
||||||
* @throws NumberParseException
|
* @throws NumberParseException
|
||||||
* @throws RecipientException
|
* @throws RecipientException
|
||||||
|
* @throws InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function __construct(string $number, string $iso2CountryCode)
|
public function __construct(string $number, string $iso2CountryCode)
|
||||||
{
|
{
|
||||||
@ -86,7 +88,7 @@ class Recipient extends StringValueObject
|
|||||||
return $this->countryCode;
|
return $this->countryCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFormatted()
|
public function getFormatted(): string
|
||||||
{
|
{
|
||||||
return ltrim(parent::getFormatted(), '+');
|
return ltrim(parent::getFormatted(), '+');
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ 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\NoSenderDefinedException;
|
||||||
use D3\LinkmobilityClient\Exceptions\RecipientException;
|
use D3\LinkmobilityClient\Exceptions\RecipientException;
|
||||||
@ -27,11 +28,12 @@ use libphonenumber\PhoneNumberUtil;
|
|||||||
class Sender extends ValueObject
|
class Sender extends ValueObject
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @param string $number
|
* @param string|null $number
|
||||||
* @param string $iso2CountryCode
|
* @param string|null $iso2CountryCode
|
||||||
*
|
*
|
||||||
* @throws RecipientException
|
|
||||||
* @throws NumberParseException
|
* @throws NumberParseException
|
||||||
|
* @throws RecipientException
|
||||||
|
* @throws InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function __construct(string $number = null, string $iso2CountryCode = null)
|
public function __construct(string $number = null, string $iso2CountryCode = null)
|
||||||
{
|
{
|
||||||
@ -67,7 +69,7 @@ class Sender extends ValueObject
|
|||||||
return PhoneNumberUtil::getInstance();
|
return PhoneNumberUtil::getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFormatted()
|
public function getFormatted(): string
|
||||||
{
|
{
|
||||||
return ltrim(parent::getFormatted(), '+');
|
return ltrim(parent::getFormatted(), '+');
|
||||||
}
|
}
|
||||||
|
@ -43,6 +43,9 @@ abstract class SmsMessageAbstract extends StringValueObject implements SmsMessag
|
|||||||
return $this->getSmsLength()->getSize();
|
return $this->getSmsLength()->getSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
public function getMessageContent()
|
public function getMessageContent()
|
||||||
{
|
{
|
||||||
return $this->get();
|
return $this->get();
|
||||||
|
@ -15,7 +15,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace D3\LinkmobilityClient\ValueObject;
|
namespace D3\LinkmobilityClient\ValueObject;
|
||||||
|
|
||||||
use InvalidArgumentException;
|
use Assert\InvalidArgumentException;
|
||||||
|
|
||||||
class SmsTextMessage extends SmsMessageAbstract
|
class SmsTextMessage extends SmsMessageAbstract
|
||||||
{
|
{
|
||||||
|
@ -15,8 +15,6 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace D3\LinkmobilityClient\ValueObject;
|
namespace D3\LinkmobilityClient\ValueObject;
|
||||||
|
|
||||||
use Assert\Assert;
|
|
||||||
|
|
||||||
abstract class StringValueObject extends ValueObject
|
abstract class StringValueObject extends ValueObject
|
||||||
{
|
{
|
||||||
public function __toString()
|
public function __toString()
|
||||||
|
@ -16,11 +16,16 @@ declare(strict_types=1);
|
|||||||
namespace D3\LinkmobilityClient\ValueObject;
|
namespace D3\LinkmobilityClient\ValueObject;
|
||||||
|
|
||||||
use Assert\Assert;
|
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)
|
public function __construct(string $number)
|
||||||
{
|
{
|
||||||
Assert::that($number)->notEmpty();
|
Assert::that($number)->notEmpty();
|
||||||
@ -33,7 +38,7 @@ abstract class ValueObject
|
|||||||
return $this->value;
|
return $this->value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFormatted()
|
public function getFormatted(): string
|
||||||
{
|
{
|
||||||
return $this->get();
|
return $this->get();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user