Compare commits

..

2 Commits

Author SHA1 Message Date
1d5ccb6d73
adjust README 2022-09-28 15:57:38 +02:00
4f3b1029f4
add support note 2022-09-08 15:46:46 +02:00
41 changed files with 300 additions and 515 deletions

View File

@ -6,7 +6,7 @@ $finder = PhpCsFixer\Finder::create()
$config = new PhpCsFixer\Config();
return $config->setRules([
'@PHP73Migration' => true,
'@PHP70Migration' => true,
'@PSR12' => true
])
->setFinder($finder)

View File

@ -4,62 +4,21 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased](https://git.d3data.de/D3Public/linkmobility-php-client/compare/2.2.0...rel_2.x)
## [Unreleased](https://git.d3data.de/D3Private/linkmobility-php-client/compare/1.3.2...rel_1.x)
## [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
## [1.3.2](https://git.d3data.de/D3Private/linkmobility-php-client/compare/1.3.1...1.3.2) - 2022-07-28
### Changed
- add support note
- adjust readme
## [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
## [1.3.1](https://git.d3data.de/D3Private/linkmobility-php-client/compare/1.3.0...1.3.1) - 2022-07-28
### Changed
- improve code quality
### Fixed
- wrong return type of LoggerHandler::getInstance
## [1.3.0](https://git.d3data.de/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
- tests added
@ -67,12 +26,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- tests use generated example phone numbers
- move recipient checks from list to recipient itself
## [1.2.1](https://git.d3data.de/D3Public/linkmobility-php-client/compare/1.2.0...1.2.1) - 2022-07-15
## [1.2.1](https://git.d3data.de/D3Private/linkmobility-php-client/compare/1.2.0...1.2.1) - 2022-07-15
### Changed
- extend log messages
- sanitize special phone number format before request
## [1.2.0](https://git.d3data.de/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
- collect exception messages in a class
- collect URI parts in a class
@ -82,14 +41,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- assign sender address type only if sender is set
- extract logger handler from client
## [1.1.0](https://git.d3data.de/D3Public/linkmobility-php-client/compare/1.0.0...1.1.0) - 2022-07-13
## [1.1.0](https://git.d3data.de/D3Private/linkmobility-php-client/compare/1.0.0...1.1.0) - 2022-07-13
### Added
- make installable in PHP 8
### Removed
- remove unused dependency
## [1.0.0](https://git.d3data.de/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
- initial implementation
- SMS requests (text or binary)

View File

@ -18,8 +18,8 @@ composer require d3/linkmobility-php-client
```
```
$client = new \D3\LinkmobilityClient\Client('personal accesstoken');
\D3\LinkmobilityClient\LoggerHandler::getInstance()->setLogger($logger); // optional
$client = new Client('personal accesstoken');
$client->setLogger($logger); // optional
$request = new D3\LinkmobilityClient\SMS\RequestFactory($message, $client)->getSmsRequest())
->addRecipient(new D3\LinkmobilityClient\ValueObject\Recipient('recipient number', 'DE'));
$response = $client->request($request)

View File

@ -18,8 +18,8 @@ composer require d3/linkmobility-php-client
```
```
$client = new \D3\LinkmobilityClient\Client('personal accesstoken');
\D3\LinkmobilityClient\LoggerHandler::getInstance()->setLogger($logger); // optional
$client = new Client('personal accesstoken');
$client->setLogger($logger); // optional
$request = new D3\LinkmobilityClient\SMS\RequestFactory($message, $client)->getSmsRequest())
->addRecipient(new D3\LinkmobilityClient\ValueObject\Recipient('recipient number', 'DE'));
$response = $client->request($request)

View File

@ -31,7 +31,7 @@ abstract class ApiTestCase extends TestCase
* @return mixed
* @throws ReflectionException
*/
public function callMethod($object, string $methodName, array $arguments = [])
public function callMethod(object $object, string $methodName, array $arguments = [])
{
$class = new ReflectionClass($object);
$method = $class->getMethod($methodName);
@ -47,7 +47,7 @@ abstract class ApiTestCase extends TestCase
* @param $value
* @throws ReflectionException
*/
public function setValue($object, string $valueName, $value)
public function setValue(object $object, string $valueName, $value)
{
$reflection = new ReflectionClass($object);
$property = $reflection->getProperty($valueName);
@ -63,7 +63,7 @@ abstract class ApiTestCase extends TestCase
* @return mixed
* @throws ReflectionException
*/
public function getValue($object, string $valueName)
public function getValue(object $object, string $valueName)
{
$reflection = new ReflectionClass($object);
$property = $reflection->getProperty($valueName);

View File

@ -17,6 +17,7 @@ namespace D3\LinkmobilityClient\Tests;
use Assert\InvalidArgumentException;
use D3\LinkmobilityClient\Client;
use D3\LinkmobilityClient\Exceptions\ApiException;
use D3\LinkmobilityClient\LoggerHandler;
use D3\LinkmobilityClient\Request\RequestInterface;
use D3\LinkmobilityClient\Response\Response;
@ -26,9 +27,11 @@ use D3\LinkmobilityClient\Url\Url;
use D3\LinkmobilityClient\Url\UrlInterface;
use GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Psr7\Response as GuzzleResponse;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Http\Message\ResponseInterface as MessageResponseInterface;
use Psr\Http\Message\StreamInterface;
use Psr\Log\AbstractLogger;
use Psr\Log\LoggerInterface;
use ReflectionException;
class ClientTest extends ApiTestCase
@ -93,32 +96,10 @@ class ClientTest extends ApiTestCase
return [
'api key only' => ['apiKey', null, 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
* @return void
@ -186,26 +167,47 @@ class ClientTest extends ApiTestCase
{
return [
'request is valid' => [true],
'request is not valid' => [false],
'request is not valid' => [false]
];
}
/**
* @test
* @param $okStatus
* @return void
* @throws ReflectionException
* @dataProvider rawRequestDataProvider
* @covers \D3\LinkmobilityClient\Client::rawRequest
*/
public function testRawRequest()
public function testRawRequest($okStatus)
{
$statusCode = $okStatus ? '200' : '301';
/** @var StreamInterface|MockObject $streamMock */
$streamMock = $this->getMockBuilder(StreamInterface::class)
->getMock();
/** @var GuzzleResponse|MockObject $responseMock */
$responseMock = $this->getMockBuilder( GuzzleResponse::class)
/** @var MessageResponseInterface|MockObject $responseMock */
$responseMock = $this->getMockBuilder(MessageResponseInterface::class)
->onlyMethods([
'getStatusCode',
'getBody',
'withStatus',
'getReasonPhrase',
'getProtocolVersion',
'withProtocolVersion',
'getHeaders',
'hasHeader',
'getHeader',
'getHeaderLine',
'withHeader',
'withAddedHeader',
'withoutHeader',
'withBody'
])
->disableOriginalConstructor()
->getMock();
$responseMock->expects($this->atLeastOnce())->method('getStatusCode')->willReturn($statusCode);
$responseMock->expects($this->atLeastOnce())
->method('getBody')->willReturn($streamMock);
@ -215,21 +217,48 @@ class ClientTest extends ApiTestCase
->getMock();
$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 */
$clientMock = $this->getMockBuilder(Client::class)
->disableOriginalConstructor()
->onlyMethods([
'getLoggerHandler',
'getLoggerHandler'
])
->getMock();
$clientMock->expects($this->atLeastOnce())
->method('getLoggerHandler')->willReturn($loggerHandlerMock);
$this->setValue($clientMock, 'requestClient', $requestClientMock);
if (false === $okStatus) {
$this->expectException(ApiException::class);
}
$this->assertSame(
$responseMock,
$this->callMethod($clientMock, 'rawRequest', ['myUrl'])
);
}
/**
* @return array
*/
public function rawRequestDataProvider(): array
{
return [
'OK status' => [true],
'NOK status' => [false],
];
}
/**
* @test
* @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'
)
);
}
}

View File

@ -7,5 +7,5 @@ composer create-project -s dev --prefer-source [--repository '{"type": "vcs", "u
# Run tests
```
./vendor/bin/phpunit [--no-coverage] [--coverage-html=cov]
./vendor/bin/phpunit [--no-coverage]
```

View File

@ -167,7 +167,7 @@ class RecipientsListTest extends ApiTestCase
$this->assertSame(
[
$this->phoneNumberFixture,
$this->phoneNumberFixture,
$this->phoneNumberFixture
],
$this->callMethod(
$this->recipientsList,
@ -280,7 +280,7 @@ class RecipientsListTest extends ApiTestCase
$this->recipientsList,
'recipients',
[
'fixture' => new stdClass(),
'fixture' => new stdClass()
]
);
@ -333,11 +333,11 @@ class RecipientsListTest extends ApiTestCase
$recipientMock = $this->getMockBuilder(Recipient::class)
->onlyMethods([
'get',
'getCountryCode',
'getCountryCode'
])
->setConstructorArgs([
$this->phoneNumberFixture,
$this->phoneCountryFixture,
$this->phoneCountryFixture
])
->getMock();
$recipientMock->method('get')->willReturn($this->phoneNumberFixture);
@ -347,11 +347,11 @@ class RecipientsListTest extends ApiTestCase
$recipientMock2 = $this->getMockBuilder(Recipient::class)
->onlyMethods([
'get',
'getCountryCode',
'getCountryCode'
])
->setConstructorArgs([
$this->phoneNumberFixture,
$this->phoneCountryFixture,
$this->phoneCountryFixture
])
->getMock();
$recipientMock2->method('get')->willReturn($this->phoneNumberFixture);
@ -359,7 +359,7 @@ class RecipientsListTest extends ApiTestCase
$list = [
'fixture' => $recipientMock,
'fixture2' => $recipientMock2,
'fixture2' => $recipientMock2
];
$this->setValue(

View File

@ -17,7 +17,6 @@ namespace D3\LinkmobilityClient\Tests\Request;
use Assert\InvalidArgumentException;
use D3\LinkmobilityClient\Client;
use D3\LinkmobilityClient\Exceptions\RecipientException;
use D3\LinkmobilityClient\RecipientsList\RecipientsListInterface;
use D3\LinkmobilityClient\Request\Request;
use D3\LinkmobilityClient\Request\RequestInterface;
@ -25,7 +24,6 @@ use D3\LinkmobilityClient\SMS\Response;
use D3\LinkmobilityClient\Tests\ApiTestCase;
use D3\LinkmobilityClient\ValueObject\Recipient;
use D3\LinkmobilityClient\ValueObject\Sender;
use libphonenumber\NumberParseException;
use libphonenumber\PhoneNumberFormat;
use libphonenumber\PhoneNumberType;
use libphonenumber\PhoneNumberUtil;
@ -89,10 +87,13 @@ abstract class AbstractRequest extends ApiTestCase
$requestMock->expects($this->atLeastOnce())->method('setMessage')->with($this->equalTo($messageMock))->willReturnSelf();
$requestMock->expects($this->atLeastOnce())->method('setClient')->with($this->equalTo($clientMock))->willReturnSelf();
$this->assertInstanceOf(
Request::class,
$this->callMethod(
$requestMock,
'__construct',
[$messageMock, $clientMock]
)
);
}
@ -114,13 +115,10 @@ abstract class AbstractRequest extends ApiTestCase
/**
* @test
* @throws ReflectionException
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::validate
* @covers \D3\LinkmobilityClient\SMS\TextRequest::validate
* @covers \D3\LinkmobilityClient\Request\Request::validate
* @return void
* @throws ReflectionException
* @throws RecipientException
* @throws NumberParseException
*/
public function validatePassedTest()
{
@ -151,12 +149,9 @@ abstract class AbstractRequest extends ApiTestCase
/**
* @test
* @throws ReflectionException
* @covers \D3\LinkmobilityClient\SMS\BinaryRequest::validate
* @covers \D3\LinkmobilityClient\SMS\TextRequest::validate
* @return void
* @throws NumberParseException
* @throws RecipientException
* @throws ReflectionException
*/
public function validateFailedTest()
{
@ -258,17 +253,17 @@ abstract class AbstractRequest extends ApiTestCase
['json' => [
'contentCategory' => 'informational',
'messageContent' => 'messageContent',
'priority' => 0,
]],
'priority' => 0
]]
],
'other' => [
'other',
[
'contentCategory' => 'informational',
'messageContent' => 'messageContent',
'priority' => 0,
],
],
'priority' => 0
]
]
];
}
@ -289,20 +284,20 @@ abstract class AbstractRequest extends ApiTestCase
['json' => [
'contentCategory' => 'informational',
'messageContent' => 'messageContent',
'priority' => 0,
'priority' => 0
]]
);
$this->assertSame(
['headers' => [
'Accept' => 'application/json',
'Content-Type' => 'application/json',
'Content-Type' => 'application/json'
],
'json' => [
'contentCategory' => 'informational',
'messageContent' => 'messageContent',
'priority' => 0,
], ],
'priority' => 0
]],
$this->callMethod(
$requestMock,
'getOptions'
@ -676,7 +671,7 @@ abstract class AbstractRequest extends ApiTestCase
/** @var StreamInterface|MockObject $streamMock */
$streamMock = $this->getMockBuilder(StreamInterface::class)
->onlyMethods(['getContents', '__toString', 'close', 'detach', 'getSize', 'tell', 'eof', 'isSeekable',
'seek', 'rewind', 'isWritable', 'write', 'isReadable', 'read', 'getMetadata', ])
'seek', 'rewind', 'isWritable', 'write', 'isReadable', 'read', 'getMetadata'])
->getMock();
$streamMock->method('getContents')->willReturn('{}');
@ -685,12 +680,12 @@ abstract class AbstractRequest extends ApiTestCase
->onlyMethods([
'getBody', 'getStatusCode', 'withStatus', 'getReasonphrase', 'getProtocolVersion',
'withProtocolVersion', 'getHeaders', 'hasHeader', 'getHeader', 'getHeaderLine',
'withHeader', 'withAddedHeader', 'withoutHeader', 'withBody', ])
'withHeader', 'withAddedHeader', 'withoutHeader', 'withBody'])
->getMock();
$rawResponseMock->method('getBody')->willReturn($streamMock);
return [
'SMS Response' => [$rawResponseMock],
'SMS Response' => [$rawResponseMock]
];
}

View File

@ -38,7 +38,7 @@ abstract class AbstractResponse extends ApiTestCase
/** @var StreamInterface|MockObject $streamMock */
$streamMock = $this->getMockBuilder(StreamInterface::class)
->onlyMethods(['getContents', '__toString', 'close', 'detach', 'getSize', 'tell', 'eof', 'isSeekable',
'seek', 'rewind', 'isWritable', 'write', 'isReadable', 'read', 'getMetadata', ])
'seek', 'rewind', 'isWritable', 'write', 'isReadable', 'read', 'getMetadata'])
->getMock();
$streamMock->expects($this->atLeastOnce())->method('getContents')->willReturn(
'{
@ -53,7 +53,7 @@ abstract class AbstractResponse extends ApiTestCase
->onlyMethods([
'getBody', 'getStatusCode', 'withStatus', 'getReasonphrase', 'getProtocolVersion',
'withProtocolVersion', 'getHeaders', 'hasHeader', 'getHeader', 'getHeaderLine',
'withHeader', 'withAddedHeader', 'withoutHeader', 'withBody', ])
'withHeader', 'withAddedHeader', 'withoutHeader', 'withBody'])
->getMock();
$rawResponseMock->method('getBody')->willReturn($streamMock);
@ -86,7 +86,7 @@ abstract class AbstractResponse extends ApiTestCase
*/
protected function checkProperties($expected, $propertyName, $methodName)
{
/** @var Response|MockObject $responseMock */
/** @var Response $response */
$responseMock = $this->getMockBuilder($this->testClassName)
->disableOriginalConstructor()
->onlyMethods(['getContent'])
@ -226,7 +226,7 @@ abstract class AbstractResponse extends ApiTestCase
{
return [
'successful' => [true, ''],
'not successful'=> [false, 'fixtureMessage'],
'not successful'=> [false, 'fixtureMessage']
];
}
}

View File

@ -100,8 +100,8 @@ class RequestFactoryTest extends ApiTestCase
public function getTextSmsRequestDataProvider(): array
{
return [
'binary' => [SmsLength::ENCODING_UCS2, BinaryRequest::class],
'ascii' => [SmsLength::ENCODING_7BIT, TextRequest::class],
'binary' => [RequestFactory::GSM_UCS2, BinaryRequest::class],
'ascii' => [RequestFactory::GSM_7BIT, TextRequest::class]
];
}

View File

@ -149,7 +149,7 @@ class RecipientTest extends ApiTestCase
}
/**
* @return array[]
* @return string[][]
*/
public function constructInvalidDataProvider(): array
{
@ -162,7 +162,7 @@ class RecipientTest extends ApiTestCase
'invalid country code' => [$phoneNumberFixture, 'DEX', true, PhoneNumberType::MOBILE, InvalidArgumentException::class],
'unparsable' => ['abc', 'DE', true, PhoneNumberType::MOBILE, NumberParseException::class],
'invalid number' => ['abcd', 'DE', false, PhoneNumberType::MOBILE, RecipientException::class],
'not mobile number' => ['abcd', 'DE', true, PhoneNumberType::FIXED_LINE, RecipientException::class],
'not mobile number' => ['abcd', 'DE', true, PhoneNumberType::FIXED_LINE, RecipientException::class]
];
}

View File

@ -16,6 +16,7 @@ declare(strict_types=1);
namespace D3\LinkmobilityClient\Tests\ValueObject;
use Assert\InvalidArgumentException;
use D3\LinkmobilityClient\Exceptions\NoSenderDefinedException;
use D3\LinkmobilityClient\Exceptions\RecipientException;
use D3\LinkmobilityClient\Tests\ApiTestCase;
use D3\LinkmobilityClient\ValueObject\Sender;
@ -29,7 +30,7 @@ use ReflectionException;
class SenderTest extends ApiTestCase
{
/** @var Sender|MockObject */
/** @var Sender */
public $sender;
private $phoneNumberFixture;
@ -48,6 +49,7 @@ class SenderTest extends ApiTestCase
$example = $phoneUtil->getExampleNumberForType($this->phoneCountryFixture, PhoneNumberType::MOBILE);
$this->phoneNumberFixture = $phoneUtil->format($example, PhoneNumberFormat::NATIONAL);
/** @var Sender|MockObject sender */
$this->sender = new Sender($this->phoneNumberFixture, $this->phoneCountryFixture);
}
@ -110,7 +112,7 @@ class SenderTest extends ApiTestCase
return [
'null number' => [null, $this->phoneCountryFixture, false],
'null country' => [$this->phoneNumberFixture, null, false],
'all values' => [$this->phoneNumberFixture, $this->phoneCountryFixture, true],
'all values' => [$this->phoneNumberFixture, $this->phoneCountryFixture, true]
];
}
@ -120,7 +122,9 @@ class SenderTest extends ApiTestCase
* @param $country
* @param $validNumber
* @param $expectedException
* @throws ReflectionException
*
* @throws NumberParseException
* @throws RecipientException
* @dataProvider constructInvalidDataProvider
* @covers \D3\LinkmobilityClient\ValueObject\Sender::__construct
*/
@ -158,7 +162,7 @@ class SenderTest extends ApiTestCase
}
/**
* @return array[]
* @return string[][]
*/
public function constructInvalidDataProvider(): array
{
@ -170,7 +174,7 @@ class SenderTest extends ApiTestCase
'empty number' => ['', 'DE', true, InvalidArgumentException::class],
'invalid country code' => [$phoneNumberFixture, 'DEX', true, InvalidArgumentException::class],
'unparsable' => ['abc', 'DE', true, NumberParseException::class],
'invalid number' => ['abcd', 'DE', false, RecipientException::class],
'invalid number' => ['abcd', 'DE', false, RecipientException::class]
];
}

View File

@ -15,13 +15,14 @@ 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\Exception\InvalidArgumentException;
use Phlib\SmsLength\SmsLength;
use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException;
class SmsBinaryMessageTest extends SmsMessageAbstractTest
class SmsBinaryMessageTest extends ApiTestCase
{
/** @var SmsBinaryMessage */
public $message;
@ -38,12 +39,21 @@ class SmsBinaryMessageTest extends SmsMessageAbstractTest
$this->message = new SmsBinaryMessage($this->messageFixture);
}
/**
* @return void
*/
public function tearDown(): void
{
parent::tearDown();
unset($this->message);
}
/**
* @test
* @return void
* @throws ReflectionException
* @covers \D3\LinkmobilityClient\ValueObject\SmsBinaryMessage::__construct
* @covers \D3\LinkmobilityClient\ValueObject\SmsMessageAbstract::__construct
*/
public function testConstructValid()
{
@ -81,7 +91,6 @@ class SmsBinaryMessageTest extends SmsMessageAbstractTest
* @throws ReflectionException
* @dataProvider constructInvalidDataProvider
* @covers \D3\LinkmobilityClient\ValueObject\SmsBinaryMessage::__construct
* @covers \D3\LinkmobilityClient\ValueObject\SmsMessageAbstract::__construct
*/
public function testConstructInvalid($binaryMessage, $valid, $expectedException)
{
@ -93,7 +102,7 @@ class SmsBinaryMessageTest extends SmsMessageAbstractTest
if ($valid) {
$smsLengthMock->expects($this->never())->method('validate')->willReturn(true);
} 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 */
@ -115,11 +124,37 @@ class SmsBinaryMessageTest extends SmsMessageAbstractTest
);
}
/**
* @return string[][]
*/
public function constructInvalidDataProvider(): array
{
return [
'empty message' => ['', true, InvalidArgumentException::class],
'invalid sms message' => ['abc', false, \Phlib\SmsLength\Exception\InvalidArgumentException::class]
];
}
/**
* @test
* @throws ReflectionException
* @covers \D3\LinkmobilityClient\ValueObject\SmsBinaryMessage::getSmsLength
*/
public function testGetSmsLengthInstance()
{
$this->assertInstanceOf(
SmsLength::class,
$this->callMethod(
$this->message,
'getSmsLength'
)
);
}
/**
* @test
* @throws ReflectionException
* @covers \D3\LinkmobilityClient\ValueObject\SmsBinaryMessage::chunkCount
* @covers \D3\LinkmobilityClient\ValueObject\SmsMessageAbstract::chunkCount
*/
public function testGetChunkCount()
{
@ -153,7 +188,6 @@ class SmsBinaryMessageTest extends SmsMessageAbstractTest
* @test
* @throws ReflectionException
* @covers \D3\LinkmobilityClient\ValueObject\SmsBinaryMessage::length
* @covers \D3\LinkmobilityClient\ValueObject\SmsMessageAbstract::length
*/
public function testGetSize()
{

View File

@ -1,65 +0,0 @@
<?php
/**
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* https://www.d3data.de
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
* @link https://www.oxidmodule.com
*/
declare(strict_types=1);
namespace D3\LinkmobilityClient\Tests\ValueObject;
use Assert\InvalidArgumentException;
use D3\LinkmobilityClient\Tests\ApiTestCase;
use D3\LinkmobilityClient\ValueObject\SmsBinaryMessage;
use Phlib\SmsLength\SmsLength;
use ReflectionException;
abstract class SmsMessageAbstractTest extends ApiTestCase
{
public $message;
/**
* @return void
*/
public function tearDown(): void
{
parent::tearDown();
unset($this->message);
}
/**
* @return array[]
*/
public function constructInvalidDataProvider(): array
{
return [
'empty message' => ['', true, InvalidArgumentException::class],
'invalid sms message' => ['abc', false, \Phlib\SmsLength\Exception\InvalidArgumentException::class],
];
}
/**
* @test
* @throws ReflectionException
* @covers \D3\LinkmobilityClient\ValueObject\SmsBinaryMessage::getSmsLength
* @covers \D3\LinkmobilityClient\ValueObject\SmsTextMessage::getSmsLength
*/
public function testGetSmsLengthInstance()
{
$this->assertInstanceOf(
SmsLength::class,
$this->callMethod(
$this->message,
'getSmsLength'
)
);
}
}

View File

@ -21,7 +21,7 @@ use Phlib\SmsLength\SmsLength;
use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException;
class SmsTextMessageTest extends SmsMessageAbstractTest
class SmsTextMessageTest extends SmsBinaryMessageTest
{
/** @var SmsTextMessage */
public $message;
@ -43,7 +43,6 @@ class SmsTextMessageTest extends SmsMessageAbstractTest
* @return void
* @throws ReflectionException
* @covers \D3\LinkmobilityClient\ValueObject\SmsTextMessage::__construct
* @covers \D3\LinkmobilityClient\ValueObject\SmsMessageAbstract::__construct
*/
public function testConstructValid()
{
@ -81,7 +80,6 @@ class SmsTextMessageTest extends SmsMessageAbstractTest
* @throws ReflectionException
* @dataProvider constructInvalidDataProvider
* @covers \D3\LinkmobilityClient\ValueObject\SmsTextMessage::__construct
* @covers \D3\LinkmobilityClient\ValueObject\SmsMessageAbstract::__construct
*/
public function testConstructInvalid($binaryMessage, $valid, $expectedException)
{
@ -114,104 +112,4 @@ class SmsTextMessageTest extends SmsMessageAbstractTest
)
);
}
/**
* @test
* @throws ReflectionException
* @covers \D3\LinkmobilityClient\ValueObject\SmsTextMessage::chunkCount
* @covers \D3\LinkmobilityClient\ValueObject\SmsMessageAbstract::chunkCount
*/
public function testGetChunkCount()
{
$expected = 2;
/** @var SmsLength|MockObject $smsLengthMock */
$smsLengthMock = $this->getMockBuilder(SmsLength::class)
->onlyMethods(['getMessageCount', 'validate'])
->disableOriginalConstructor()
->getMock();
$smsLengthMock->expects($this->once())->method('getMessageCount')->willReturn($expected);
$smsLengthMock->method('validate')->willReturn(true);
/** @var SmsTextMessage|MockObject $message */
$message = $this->getMockBuilder(SmsTextMessage::class)
->onlyMethods(['getSmsLength'])
->disableOriginalConstructor()
->getMock();
$message->method('getSmsLength')->willReturn($smsLengthMock);
$this->assertSame(
$expected,
$this->callMethod(
$message,
'chunkCount'
)
);
}
/**
* @test
* @throws ReflectionException
* @covers \D3\LinkmobilityClient\ValueObject\SmsTextMessage::length
* @covers \D3\LinkmobilityClient\ValueObject\SmsMessageAbstract::length
*/
public function testGetSize()
{
$expected = 55;
/** @var SmsLength|MockObject $smsLengthMock */
$smsLengthMock = $this->getMockBuilder(SmsLength::class)
->onlyMethods(['getSize', 'validate'])
->disableOriginalConstructor()
->getMock();
$smsLengthMock->expects($this->once())->method('getSize')->willReturn($expected);
$smsLengthMock->method('validate')->willReturn(true);
/** @var SmsTextMessage|MockObject $message */
$message = $this->getMockBuilder(SmsTextMessage::class)
->onlyMethods(['getSmsLength'])
->disableOriginalConstructor()
->getMock();
$message->method('getSmsLength')->willReturn($smsLengthMock);
$this->assertSame(
$expected,
$this->callMethod(
$message,
'length'
)
);
}
/**
* @test
* @throws ReflectionException
* @covers \D3\LinkmobilityClient\ValueObject\SmsTextMessage::getMessageContent
* @covers \D3\LinkmobilityClient\ValueObject\SmsMessageAbstract::getMessageContent
*/
public function testGetMessageContent()
{
/** @var SmsLength|MockObject $smsLengthMock */
$smsLengthMock = $this->getMockBuilder(SmsLength::class)
->onlyMethods(['validate'])
->disableOriginalConstructor()
->getMock();
$smsLengthMock->method('validate')->willReturn(true);
/** @var SmsTextMessage|MockObject $message */
$message = $this->getMockBuilder(SmsTextMessage::class)
->onlyMethods(['getSmsLength'])
->disableOriginalConstructor()
->getMock();
$message->method('getSmsLength')->willReturn($smsLengthMock);
$message->__construct($this->messageFixture);
$this->assertSame(
'testMessage',
$this->callMethod(
$message,
'getMessageContent'
)
);
}
}

View File

@ -16,8 +16,13 @@ declare(strict_types=1);
namespace D3\LinkmobilityClient\Tests\ValueObject;
use Assert\InvalidArgumentException;
use D3\LinkmobilityClient\Exceptions\NoSenderDefinedException;
use D3\LinkmobilityClient\Exceptions\RecipientException;
use D3\LinkmobilityClient\Tests\ApiTestCase;
use D3\LinkmobilityClient\ValueObject\Sender;
use D3\LinkmobilityClient\ValueObject\ValueObject;
use libphonenumber\NumberParseException;
use libphonenumber\PhoneNumber;
use libphonenumber\PhoneNumberFormat;
use libphonenumber\PhoneNumberType;
use libphonenumber\PhoneNumberUtil;
@ -26,13 +31,11 @@ use ReflectionException;
class ValueObjectTest extends ApiTestCase
{
/** @var ValueObject|MockObject */
public $value;
public function setUp(): void
{
parent::setUp();
/** @var ValueObject|MockObject value */
$this->value = $this->getMockBuilder(ValueObject::class)
->disableOriginalConstructor()
->getMock();

View File

@ -21,20 +21,18 @@
"GPL-3.0-or-later"
],
"require": {
"php": "^7.3 || ^8.0.3",
"beberlei/assert": "^3.3",
"guzzlehttp/guzzle": "^7.3",
"psr/http-message": "^1.0 || ^2.0",
"phlib/sms-length": "^2.0",
"php": "^7.0 || ^8.0",
"beberlei/assert": "^2.9.9",
"guzzlehttp/guzzle": "~6.2 || ^7.4",
"psr/http-message": "~1.0",
"phlib/sms-length": "^1.1.0 || ^2.0.0",
"giggsey/libphonenumber-for-php": "^8.12.50",
"caseyamcl/guzzle_retry_middleware": "^2.8",
"ext-json": "*"
},
"require-dev": {
"php": "^7.4 || ~8.0.3",
"phpunit/phpunit" : "^9.5",
"friendsofphp/php-cs-fixer": "^3.9",
"phpstan/phpstan": "^1.8"
"php": "^7.2",
"phpunit/phpunit" : "^8.0",
"friendsofphp/php-cs-fixer": "^2.0"
},
"autoload": {
"psr-4": {
@ -43,9 +41,8 @@
}
},
"scripts": {
"test": "./vendor/bin/phpunit",
"test": "phpunit",
"check-style": "./vendor/bin/php-cs-fixer fix --verbose --dry-run",
"fix-style": "./vendor/bin/php-cs-fixer fix --verbose",
"check-code": "./vendor/bin/phpstan analyse -c phpstan.neon --no-progress --ansi"
"fix-style": "./vendor/bin/php-cs-fixer fix --verbose"
}
}

View File

@ -1,6 +0,0 @@
parameters:
paths:
- src
- Tests
level: 5
phpVersion: 70300

View File

@ -1,20 +1,22 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<phpunit
bootstrap="vendor/autoload.php"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">src</directory>
</include>
<report>
<clover outputFile="build/logs/clover.xml"/>
</report>
</coverage>
convertWarningsToExceptions="true">
<testsuite name="linkmobility">
<directory>./Tests</directory>
</testsuite>
<logging/>
<filter>
<whitelist>
<directory suffix=".php">src</directory>
</whitelist>
</filter>
<logging>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
</phpunit>

View File

@ -15,17 +15,14 @@ declare(strict_types=1);
namespace D3\LinkmobilityClient;
use Assert\InvalidArgumentException;
use D3\LinkmobilityClient\Exceptions\ApiException;
use D3\LinkmobilityClient\Exceptions\ExceptionMessages;
use D3\LinkmobilityClient\Request\RequestInterface;
use D3\LinkmobilityClient\Url\Url;
use D3\LinkmobilityClient\Url\UrlInterface;
use GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\MessageFormatter;
use GuzzleHttp\Middleware;
use GuzzleRetry\GuzzleRetryMiddleware;
use InvalidArgumentException;
use Psr\Http\Message\ResponseInterface;
class Client
@ -38,28 +35,14 @@ class Client
{
$this->accessToken = $accessToken;
$this->apiUrl = $apiUrl ?: new Url();
$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
]);
$this->requestClient = $client ?: new \GuzzleHttp\Client([ 'base_uri' => $this->apiUrl->getBaseUri() ]);
}
/**
* @param RequestInterface $request
*
* @return Response\ResponseInterface
* @throws ApiException
* @throws GuzzleException
* @throws InvalidArgumentException
*/
@ -78,14 +61,30 @@ class Client
* @param array $options
*
* @return ResponseInterface
* @throws ApiException
* @throws GuzzleException
*/
protected function rawRequest($url, string $method = RequestInterface::METHOD_GET, array $options = []): ResponseInterface
{
$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();
$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;
}
@ -97,28 +96,4 @@ class Client
{
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
]);
}
}

View 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
{
}

View File

@ -42,7 +42,7 @@ class LoggerHandler
}
/**
* @param LoggerInterface $logger
* @param mixed $logger
*/
public function setLogger(LoggerInterface $logger)
{

View File

@ -31,16 +31,10 @@ class RecipientsList implements RecipientsListInterface, Iterator
*/
private $recipients = [];
/**
* @deprecated unused client parameter will remove
* @param Client|null $client
*/
public function __construct(Client $client = null)
public function __construct(Client $client)
{
if ($client) {
$this->setClient($client);
}
}
/**
* @param Recipient $recipient
@ -119,7 +113,6 @@ class RecipientsList implements RecipientsListInterface, Iterator
}
/**
* @deprecated
* @return Client
*/
public function getClient(): Client
@ -128,7 +121,6 @@ class RecipientsList implements RecipientsListInterface, Iterator
}
/**
* @deprecated
* @param Client $client
*
* @return RecipientsList

View File

@ -20,10 +20,6 @@ use D3\LinkmobilityClient\ValueObject\Recipient;
interface RecipientsListInterface
{
/**
* @deprecated unused client parameter will remove
* @param Client $client
*/
public function __construct(Client $client);
public function add(Recipient $recipient): RecipientsListInterface;
@ -31,6 +27,4 @@ interface RecipientsListInterface
public function clearRecipents(): RecipientsListInterface;
public function getRecipients(): array;
public function getRecipientsList(): array;
}

View File

@ -16,7 +16,6 @@ declare(strict_types=1);
namespace D3\LinkmobilityClient\Request;
use Assert\Assert;
use Assert\InvalidArgumentException;
use D3\LinkmobilityClient\Client;
use D3\LinkmobilityClient\Exceptions\ExceptionMessages;
use D3\LinkmobilityClient\RecipientsList\RecipientsList;
@ -26,7 +25,9 @@ use D3\LinkmobilityClient\ValueObject\Recipient;
use D3\LinkmobilityClient\ValueObject\Sender;
use D3\LinkmobilityClient\ValueObject\SmsMessageAbstract;
use D3\LinkmobilityClient\ValueObject\SmsMessageInterface;
use D3\LinkmobilityClient\ValueObject\StringValueObject;
use GuzzleHttp\RequestOptions;
use InvalidArgumentException;
abstract class Request implements RequestInterface
{
@ -106,7 +107,7 @@ abstract class Request implements RequestInterface
private $test = false;
/**
* @var int
* @var bool
*/
private $maxSmsPerMessage = 0;
@ -118,6 +119,8 @@ abstract class Request implements RequestInterface
$this->recipientsList = new RecipientsList($client);
$this->setMessage($message);
$this->setClient($client);
return $this;
}
/**
@ -166,7 +169,7 @@ abstract class Request implements RequestInterface
'senderAddress' => $this->getSenderAddress() ? $this->getSenderAddress()->getFormatted() : null,
'senderAddressType' => $this->getSenderAddressType(),
'test' => $this->getTestMode(),
'validityPeriode' => $this->getValidityPeriode(),
'validityPeriode' => $this->getValidityPeriode()
];
}
@ -197,18 +200,18 @@ abstract class Request implements RequestInterface
'headers' => [
'Accept' => $this->contentType,
'Content-Type' => $this->contentType,
],
]
],
$this->getBody()
);
}
/**
* @param SmsMessageInterface $message
* @param StringValueObject $message
*
* @return $this
*/
public function setMessage(SmsMessageInterface $message): Request
public function setMessage(StringValueObject $message): Request
{
$this->message = $message;
@ -277,7 +280,7 @@ abstract class Request implements RequestInterface
return $this;
}
public function getClientMessageId(): ?string
public function getClientMessageId()
{
return $this->clientMessageId;
}
@ -303,7 +306,7 @@ abstract class Request implements RequestInterface
{
return [
RequestInterface::CONTENTCATEGORY_ADVERTISEMENT => RequestInterface::CONTENTCATEGORY_ADVERTISEMENT,
RequestInterface::CONTENTCATEGORY_INFORMATIONAL => RequestInterface::CONTENTCATEGORY_INFORMATIONAL,
RequestInterface::CONTENTCATEGORY_INFORMATIONAL => RequestInterface::CONTENTCATEGORY_INFORMATIONAL
];
}
@ -373,7 +376,7 @@ abstract class Request implements RequestInterface
/**
* @return string|null
*/
public function getNotificationCallbackUrl(): ?string
public function getNotificationCallbackUrl()
{
return $this->notificationCallbackUrl;
}
@ -393,7 +396,7 @@ abstract class Request implements RequestInterface
/**
* @return int|null
*/
public function getPriority(): ?int
public function getPriority()
{
return $this->priority;
}
@ -419,7 +422,7 @@ abstract class Request implements RequestInterface
}
/**
* @return bool
* @return bool|null
*/
public function doSendAsFlashSms(): bool
{
@ -441,7 +444,7 @@ abstract class Request implements RequestInterface
/**
* @return Sender|null
*/
public function getSenderAddress(): ?Sender
public function getSenderAddress()
{
return $this->senderAddress;
}
@ -461,7 +464,7 @@ abstract class Request implements RequestInterface
/**
* @return string|null
*/
public function getSenderAddressType(): ?string
public function getSenderAddressType()
{
return $this->getSenderAddress() && $this->getSenderAddress()->get() ? $this->senderAddressType : null;
}
@ -475,7 +478,7 @@ abstract class Request implements RequestInterface
RequestInterface::SENDERADDRESSTYPE_ALPHANUMERIC => RequestInterface::SENDERADDRESSTYPE_ALPHANUMERIC,
RequestInterface::SENDERADDRESSTYPE_INTERNATIONAL => RequestInterface::SENDERADDRESSTYPE_INTERNATIONAL,
RequestInterface::SENDERADDRESSTYPE_NATIONAL => RequestInterface::SENDERADDRESSTYPE_NATIONAL,
RequestInterface::SENDERADDRESSTYPE_SHORTCODE => RequestInterface::SENDERADDRESSTYPE_SHORTCODE,
RequestInterface::SENDERADDRESSTYPE_SHORTCODE => RequestInterface::SENDERADDRESSTYPE_SHORTCODE
];
}
@ -494,7 +497,7 @@ abstract class Request implements RequestInterface
/**
* @return int|null
*/
public function getValidityPeriode(): ?int
public function getValidityPeriode()
{
return $this->validityPeriode;
}
@ -520,7 +523,6 @@ abstract class Request implements RequestInterface
/**
* @param Client $client
* @return Request
*/
public function setClient(Client $client): Request
{

View File

@ -15,16 +15,15 @@ declare(strict_types=1);
namespace D3\LinkmobilityClient\Request;
use Assert\InvalidArgumentException;
use D3\LinkmobilityClient\Client;
use D3\LinkmobilityClient\RecipientsList\RecipientsListInterface;
use D3\LinkmobilityClient\ValueObject\SmsMessageInterface;
use InvalidArgumentException;
use Psr\Http\Message\ResponseInterface as PsrResponseInterface;
use D3\LinkmobilityClient\Response\ResponseInterface as LMResponseInterface;
interface RequestInterface
{
// @codeCoverageIgnoreStart
public const METHOD_GET = 'GET';
public const METHOD_POST = 'POST';
public const METHOD_PUT = 'PUT';
@ -43,7 +42,6 @@ interface RequestInterface
public const SENDERADDRESSTYPE_INTERNATIONAL = 'international';
public const SENDERADDRESSTYPE_ALPHANUMERIC = 'alphanumeric';
public const SENDERADDRESSTYPE_SHORTCODE = 'shortcode';
// @codeCoverageIgnoreEnd
/**
* @param SmsMessageInterface $message

View File

@ -72,7 +72,7 @@ abstract class Response implements ResponseInterface
/**
* @return string|null
*/
public function getClientMessageId(): ?string
public function getClientMessageId()
{
return $this->getContent()[self::CLIENTMESSAGEID];
}
@ -80,13 +80,13 @@ abstract class Response implements ResponseInterface
/**
* @return string|null
*/
public function getTransferId(): ?string
public function getTransferId()
{
return $this->getContent()[self::TRANSFERID];
}
/**
* @return int
* @return string|null
*/
public function getSmsCount(): int
{

View File

@ -16,10 +16,10 @@ declare(strict_types=1);
namespace D3\LinkmobilityClient\SMS;
use Assert\Assert;
use Assert\InvalidArgumentException;
use D3\LinkmobilityClient\Request\Request;
use D3\LinkmobilityClient\Url\Url;
use D3\LinkmobilityClient\ValueObject\SmsBinaryMessage;
use InvalidArgumentException;
class BinaryRequest extends Request implements SmsRequestInterface
{
@ -36,7 +36,7 @@ class BinaryRequest extends Request implements SmsRequestInterface
return array_merge(
parent::getRawBody(),
[
'userDataHeaderPresent' => true,
'userDataHeaderPresent' => true
]
);
}

View File

@ -20,15 +20,21 @@ use D3\LinkmobilityClient\ValueObject\SmsBinaryMessage;
use D3\LinkmobilityClient\ValueObject\SmsTextMessage;
use Phlib\SmsLength\SmsLength;
class RequestFactory implements RequestFactoryInterface
class RequestFactory
{
/**
* @deprecated is SmsLength constant from version 2.1
*/
public const GSM_7BIT = '7-bit';
/**
* @deprecated is SmsLength constant from version 2.1
*/
public const GSM_UCS2 = 'ucs-2';
protected $message;
protected $client;
/**
* @param $message
* @param Client $client
*/
public function __construct($message, Client $client)
{
$this->message = $message;
@ -40,7 +46,7 @@ class RequestFactory implements RequestFactoryInterface
*/
public function getSmsRequest(): SmsRequestInterface
{
if ($this->getSmsLength()->getEncoding() === SmsLength::ENCODING_7BIT) {
if ($this->getSmsLength()->getEncoding() === self::GSM_7BIT) {
$message = new SmsTextMessage($this->message);
return new TextRequest($message, $this->client);
}

View File

@ -15,11 +15,9 @@ declare(strict_types=1);
namespace D3\LinkmobilityClient\SMS;
use D3\LinkmobilityClient\Client;
interface RequestFactoryInterface
{
public function __construct($message, Client $client);
public function __construct($message);
public function getSmsRequest(): SmsRequestInterface;
public function getRequest(): SmsRequestInterface;
}

View File

@ -15,8 +15,6 @@ declare(strict_types=1);
namespace D3\LinkmobilityClient\SMS;
use D3\LinkmobilityClient\Response\Response as BaseResponse;
class Response extends BaseResponse
class Response extends \D3\LinkmobilityClient\Response\Response
{
}

View File

@ -16,10 +16,10 @@ declare(strict_types=1);
namespace D3\LinkmobilityClient\SMS;
use Assert\Assert;
use Assert\InvalidArgumentException;
use D3\LinkmobilityClient\Request\Request;
use D3\LinkmobilityClient\Url\Url;
use D3\LinkmobilityClient\ValueObject\SmsTextMessage;
use InvalidArgumentException;
class TextRequest extends Request implements SmsRequestInterface
{

View File

@ -30,7 +30,7 @@ class Url implements UrlInterface
/**
* @return string
*/
public function getTextSmsUri(): string
public function getTextSmsUri()
{
return '/rest/smsmessaging/text';
}
@ -38,7 +38,7 @@ class Url implements UrlInterface
/**
* @return string
*/
public function getBinarySmsUri(): string
public function getBinarySmsUri()
{
return '/rest/smsmessaging/binary';
}

View File

@ -18,8 +18,4 @@ namespace D3\LinkmobilityClient\Url;
interface UrlInterface
{
public function getBaseUri(): string;
public function getTextSmsUri(): string;
public function getBinarySmsUri(): string;
}

View File

@ -16,7 +16,6 @@ declare(strict_types=1);
namespace D3\LinkmobilityClient\ValueObject;
use Assert\Assert;
use Assert\InvalidArgumentException;
use D3\LinkmobilityClient\Exceptions\ExceptionMessages;
use D3\LinkmobilityClient\Exceptions\RecipientException;
use libphonenumber\NumberParseException;
@ -31,7 +30,7 @@ class Recipient extends StringValueObject
*/
protected $allowedNumberTypes = [
PhoneNumberType::MOBILE,
PhoneNumberType::FIXED_LINE_OR_MOBILE,
PhoneNumberType::FIXED_LINE_OR_MOBILE
];
/**
@ -45,7 +44,6 @@ class Recipient extends StringValueObject
*
* @throws NumberParseException
* @throws RecipientException
* @throws InvalidArgumentException
*/
public function __construct(string $number, string $iso2CountryCode)
{
@ -88,7 +86,7 @@ class Recipient extends StringValueObject
return $this->countryCode;
}
public function getFormatted(): string
public function getFormatted()
{
return ltrim(parent::getFormatted(), '+');
}

View File

@ -16,7 +16,6 @@ declare(strict_types=1);
namespace D3\LinkmobilityClient\ValueObject;
use Assert\Assert;
use Assert\InvalidArgumentException;
use D3\LinkmobilityClient\Exceptions\ExceptionMessages;
use D3\LinkmobilityClient\Exceptions\NoSenderDefinedException;
use D3\LinkmobilityClient\Exceptions\RecipientException;
@ -28,12 +27,11 @@ use libphonenumber\PhoneNumberUtil;
class Sender extends ValueObject
{
/**
* @param string|null $number
* @param string|null $iso2CountryCode
* @param string $number
* @param string $iso2CountryCode
*
* @throws NumberParseException
* @throws RecipientException
* @throws InvalidArgumentException
* @throws NumberParseException
*/
public function __construct(string $number = null, string $iso2CountryCode = null)
{
@ -69,7 +67,7 @@ class Sender extends ValueObject
return PhoneNumberUtil::getInstance();
}
public function getFormatted(): string
public function getFormatted()
{
return ltrim(parent::getFormatted(), '+');
}

View File

@ -43,9 +43,6 @@ abstract class SmsMessageAbstract extends StringValueObject implements SmsMessag
return $this->getSmsLength()->getSize();
}
/**
* @return mixed
*/
public function getMessageContent()
{
return $this->get();

View File

@ -15,7 +15,7 @@ declare(strict_types=1);
namespace D3\LinkmobilityClient\ValueObject;
use Assert\InvalidArgumentException;
use InvalidArgumentException;
class SmsTextMessage extends SmsMessageAbstract
{

View File

@ -15,6 +15,8 @@ declare(strict_types=1);
namespace D3\LinkmobilityClient\ValueObject;
use Assert\Assert;
abstract class StringValueObject extends ValueObject
{
public function __toString()

View File

@ -16,16 +16,11 @@ declare(strict_types=1);
namespace D3\LinkmobilityClient\ValueObject;
use Assert\Assert;
use Assert\InvalidArgumentException;
abstract class ValueObject
{
protected $value;
/**
* @param string $number
* @throws InvalidArgumentException
*/
public function __construct(string $number)
{
Assert::that($number)->notEmpty();
@ -38,7 +33,7 @@ abstract class ValueObject
return $this->value;
}
public function getFormatted(): string
public function getFormatted()
{
return $this->get();
}