Compare commits
No commits in common. "main" and "2.0.3" have entirely different histories.
44
CHANGELOG.md
44
CHANGELOG.md
@ -4,40 +4,18 @@ 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/D3Public/linkmobility-php-client/compare/2.2.0...rel_2.x)
|
## [Unreleased](https://git.d3data.de/D3Private/linkmobility-php-client/compare/2.0.3...rel_2.x)
|
||||||
|
|
||||||
## [2.2.0](https://git.d3data.de/D3Public/linkmobility-php-client/compare/2.1.0...2.2.0) - 2023-06-29
|
## [2.0.3](https://git.d3data.de/D3Private/linkmobility-php-client/compare/2.0.2...2.0.3) - 2022-12-26
|
||||||
### 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
|
### Changed
|
||||||
- allow Guzzle v7.3 for more backward compatibility
|
- 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
|
## [2.0.2](https://git.d3data.de/D3Private/linkmobility-php-client/compare/2.0.1...2.0.2) - 2022-07-28
|
||||||
### Changed
|
### Changed
|
||||||
- add support note
|
- add support note
|
||||||
- adjust readme
|
- adjust readme
|
||||||
|
|
||||||
## [2.0.1](https://git.d3data.de/D3Public/linkmobility-php-client/compare/2.0.0...2.0.1) - 2022-07-28
|
## [2.0.1](https://git.d3data.de/D3Private/linkmobility-php-client/compare/2.0.0...2.0.1) - 2022-07-28
|
||||||
### Added
|
### Added
|
||||||
- phpstan code checks
|
- phpstan code checks
|
||||||
|
|
||||||
@ -48,18 +26,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
### Fixed
|
### Fixed
|
||||||
- wrong return type of LoggerHandler::getInstance
|
- 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
|
## [2.0.0](https://git.d3data.de/D3Private/linkmobility-php-client/compare/1.3.0...2.0.0) - 2022-07-19
|
||||||
### Changed
|
### Changed
|
||||||
- adjust to PHP >= 7.3 and current dependency packages
|
- 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
|
## [1.3.1](https://git.d3data.de/D3Private/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/D3Public/linkmobility-php-client/compare/1.2.1...1.3.0) - 2022-07-18
|
## [1.3.0](https://git.d3data.de/D3Private/linkmobility-php-client/compare/1.2.1...1.3.0) - 2022-07-18
|
||||||
### Added
|
### Added
|
||||||
- tests added
|
- tests added
|
||||||
|
|
||||||
@ -67,12 +45,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/D3Public/linkmobility-php-client/compare/1.2.0...1.2.1) - 2022-07-15
|
## [1.2.1](https://git.d3data.de/D3Private/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/D3Public/linkmobility-php-client/compare/1.1.0...1.2.0) - 2022-07-14
|
## [1.2.0](https://git.d3data.de/D3Private/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
|
||||||
@ -82,14 +60,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/D3Public/linkmobility-php-client/compare/1.0.0...1.1.0) - 2022-07-13
|
## [1.1.0](https://git.d3data.de/D3Private/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/D3Public/linkmobility-php-client/releases/tag/1.0.0) - 2022-07-13
|
## [1.0.0](https://git.d3data.de/D3Private/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)
|
||||||
|
@ -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)
|
||||||
|
@ -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)
|
||||||
|
@ -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,6 +17,7 @@ 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;
|
||||||
@ -26,9 +27,11 @@ 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
|
||||||
@ -97,28 +100,6 @@ class ClientTest extends ApiTestCase
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @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
|
||||||
@ -192,20 +173,41 @@ class ClientTest extends ApiTestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @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()
|
public function testRawRequest($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())->method('getStatusCode')->willReturn($statusCode);
|
||||||
$responseMock->expects($this->atLeastOnce())
|
$responseMock->expects($this->atLeastOnce())
|
||||||
->method('getBody')->willReturn($streamMock);
|
->method('getBody')->willReturn($streamMock);
|
||||||
|
|
||||||
@ -215,6 +217,17 @@ 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()
|
||||||
@ -222,14 +235,30 @@ class ClientTest extends ApiTestCase
|
|||||||
'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
|
||||||
@ -246,38 +275,4 @@ 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] [--coverage-html=cov]
|
./vendor/bin/phpunit [--no-coverage]
|
||||||
```
|
```
|
||||||
|
@ -15,8 +15,9 @@ 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;
|
||||||
@ -93,7 +94,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 */
|
||||||
|
@ -19,6 +19,7 @@ use Assert\InvalidArgumentException;
|
|||||||
use D3\LinkmobilityClient\Tests\ApiTestCase;
|
use D3\LinkmobilityClient\Tests\ApiTestCase;
|
||||||
use D3\LinkmobilityClient\ValueObject\SmsBinaryMessage;
|
use D3\LinkmobilityClient\ValueObject\SmsBinaryMessage;
|
||||||
use Phlib\SmsLength\SmsLength;
|
use Phlib\SmsLength\SmsLength;
|
||||||
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
use ReflectionException;
|
use ReflectionException;
|
||||||
|
|
||||||
abstract class SmsMessageAbstractTest extends ApiTestCase
|
abstract class SmsMessageAbstractTest extends ApiTestCase
|
||||||
|
@ -21,13 +21,12 @@
|
|||||||
"GPL-3.0-or-later"
|
"GPL-3.0-or-later"
|
||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^7.3 || ^8.0.3",
|
"php": "^7.3 || ~8.0.3",
|
||||||
"beberlei/assert": "^3.3",
|
"beberlei/assert": "^3.3",
|
||||||
"guzzlehttp/guzzle": "^7.3",
|
"guzzlehttp/guzzle": "^7.3",
|
||||||
"psr/http-message": "^1.0 || ^2.0",
|
"psr/http-message": "~1.0",
|
||||||
"phlib/sms-length": "^2.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": {
|
||||||
|
@ -15,17 +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\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 GuzzleHttp\HandlerStack;
|
use InvalidArgumentException;
|
||||||
use GuzzleHttp\MessageFormatter;
|
|
||||||
use GuzzleHttp\Middleware;
|
|
||||||
use GuzzleRetry\GuzzleRetryMiddleware;
|
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
|
||||||
class Client
|
class Client
|
||||||
@ -38,28 +35,14 @@ class Client
|
|||||||
{
|
{
|
||||||
$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,14 +61,30 @@ 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);
|
$this->getLoggerHandler()->getLogger()->debug('linkmobility request: '.$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();
|
$response->getBody()->rewind();
|
||||||
|
$this->getLoggerHandler()->getLogger()->error($message, [$response->getBody()->getContents()]);
|
||||||
|
throw new ApiException($message);
|
||||||
|
}
|
||||||
|
|
||||||
|
$response->getBody()->rewind();
|
||||||
|
$this->getLoggerHandler()->getLogger()->debug('response', [$response->getBody()->getContents()]);
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
@ -97,28 +96,4 @@ 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
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
20
src/Exceptions/ApiException.php
Normal file
20
src/Exceptions/ApiException.php
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*
|
||||||
|
* https://www.d3data.de
|
||||||
|
*
|
||||||
|
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
||||||
|
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
|
||||||
|
* @link https://www.oxidmodule.com
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace D3\LinkmobilityClient\Exceptions;
|
||||||
|
|
||||||
|
class ApiException extends LinkmobilityException
|
||||||
|
{
|
||||||
|
}
|
@ -31,15 +31,9 @@ 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 );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -119,7 +113,6 @@ class RecipientsList implements RecipientsListInterface, Iterator
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated
|
|
||||||
* @return Client
|
* @return Client
|
||||||
*/
|
*/
|
||||||
public function getClient(): Client
|
public function getClient(): Client
|
||||||
@ -128,7 +121,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,7 +16,6 @@ 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;
|
||||||
@ -26,7 +25,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
|
||||||
{
|
{
|
||||||
|
@ -15,16 +15,15 @@ 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';
|
||||||
@ -43,7 +42,6 @@ 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
|
||||||
|
@ -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
|
||||||
{
|
{
|
||||||
|
@ -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
|
||||||
{
|
{
|
||||||
|
@ -16,7 +16,6 @@ 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;
|
||||||
@ -45,7 +44,6 @@ 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)
|
||||||
{
|
{
|
||||||
|
@ -16,7 +16,6 @@ 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;
|
||||||
@ -33,7 +32,6 @@ class Sender extends ValueObject
|
|||||||
*
|
*
|
||||||
* @throws NumberParseException
|
* @throws NumberParseException
|
||||||
* @throws RecipientException
|
* @throws RecipientException
|
||||||
* @throws InvalidArgumentException
|
|
||||||
*/
|
*/
|
||||||
public function __construct(string $number = null, string $iso2CountryCode = null)
|
public function __construct(string $number = null, string $iso2CountryCode = null)
|
||||||
{
|
{
|
||||||
|
@ -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
|
||||||
{
|
{
|
||||||
|
@ -16,16 +16,11 @@ 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();
|
||||||
|
Loading…
Reference in New Issue
Block a user