Compare commits
21 Commits
Author | SHA1 | Date | |
---|---|---|---|
df33a97084
|
|||
222770bec9
|
|||
8f70d40640
|
|||
cd4e3b6277
|
|||
f4d5e54448
|
|||
0d589f3878
|
|||
4cd0ab0d17
|
|||
1a9389d763
|
|||
491c260870
|
|||
50d2276a78
|
|||
3932246fbd
|
|||
3338d70562
|
|||
229d961bb8
|
|||
fed8040fcb
|
|||
b33b6081ad
|
|||
d07eb1f694
|
|||
c8ca412c14
|
|||
ff0784ce46
|
|||
7e43fa1537
|
|||
b22da1bd4a
|
|||
95b95d1d8b
|
@ -6,7 +6,7 @@ $finder = PhpCsFixer\Finder::create()
|
||||
|
||||
$config = new PhpCsFixer\Config();
|
||||
return $config->setRules([
|
||||
'@PHP70Migration' => true,
|
||||
'@PHP73Migration' => true,
|
||||
'@PSR12' => true
|
||||
])
|
||||
->setFinder($finder)
|
||||
|
73
CHANGELOG.md
73
CHANGELOG.md
@ -1,42 +1,71 @@
|
||||
# Changelog
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
---
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## 1.3.0.0 (2022-07-18)
|
||||
## [Unreleased](https://git.d3data.de/D3Private/linkmobility-php-client/compare/2.0.2...rel_2.x)
|
||||
|
||||
- tests use generated example phone numbers
|
||||
- move recipient checks from list to recipient itself
|
||||
## [2.0.2](https://git.d3data.de/D3Private/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/D3Private/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/D3Private/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/D3Private/linkmobility-php-client/compare/1.3.0...1.3.1) - 2022-07-28
|
||||
### Changed
|
||||
- improve code quality
|
||||
|
||||
### Fixed
|
||||
- wrong return type of LoggerHandler::getInstance
|
||||
|
||||
## [1.3.0](https://git.d3data.de/D3Private/linkmobility-php-client/compare/1.2.1...1.3.0) - 2022-07-18
|
||||
### Added
|
||||
- tests added
|
||||
|
||||
---
|
||||
|
||||
## 1.2.1.0 (2022-07-15)
|
||||
### Changed
|
||||
- tests use generated example phone numbers
|
||||
- move recipient checks from list to recipient itself
|
||||
|
||||
## [1.2.1](https://git.d3data.de/D3Private/linkmobility-php-client/compare/1.2.0...1.2.1) - 2022-07-15
|
||||
### Changed
|
||||
- extend log messages
|
||||
- sanitize special phone number format before request
|
||||
|
||||
---
|
||||
|
||||
## 1.2.0.0 (2022-07-14)
|
||||
|
||||
- make sender number optional
|
||||
- assign sender address type only if sender is set
|
||||
## [1.2.0](https://git.d3data.de/D3Private/linkmobility-php-client/compare/1.1.0...1.2.0) - 2022-07-14
|
||||
### Added
|
||||
- collect exception messages in a class
|
||||
- collect URI parts in a class
|
||||
|
||||
### Changed
|
||||
- make sender number optional
|
||||
- assign sender address type only if sender is set
|
||||
- extract logger handler from client
|
||||
|
||||
---
|
||||
|
||||
## 1.1.0.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.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)
|
||||
- SMS responses
|
||||
- recipient managing
|
||||
- recipient managing
|
||||
|
@ -1,7 +1,7 @@
|
||||
[](README.md)
|
||||
[](README.en.md)
|
||||
|
||||
# LINK Mobility Austria PHP API Client
|
||||
# LINK Mobility PHP API Client
|
||||
|
||||
[LINK Mobility](https://www.linkmobility.de/) provides a service for sending mobile messages (SMS, Whatsapp, RCS, Chatbot, ...).
|
||||
|
||||
@ -39,6 +39,12 @@ If you have a suggestion that would make this better, please fork the repo and c
|
||||
- Push to the Branch (git push origin feature/AmazingFeature)
|
||||
- Open a Pull Request
|
||||
|
||||
## Support
|
||||
|
||||
If you have any questions about the *messaging service* and its *contracts*, please contact the [LINK Mobility Team](https://www.linkmobility.de/kontakt).
|
||||
|
||||
For *technical inquiries* you will find the contact options in the [composer.json](composer.json).
|
||||
|
||||
## License
|
||||
(status: 2022-07-13)
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
[](README.md)
|
||||
[](README.en.md)
|
||||
|
||||
# LINK Mobility Austria PHP API Client
|
||||
# LINK Mobility PHP API Client
|
||||
|
||||
[LINK Mobility](https://www.linkmobility.de/) stellt einen Service zum Versenden von mobilen Nachrichten (SMS, Whatsapp, RCS, Chatbot, ...) zur VerfĂĽgung.
|
||||
|
||||
@ -39,6 +39,12 @@ Wenn Sie eine Verbesserungsvorschlag haben, legen Sie einen Fork des Respoitorie
|
||||
- Ăśbertragen Sie den Branch (git push origin feature/AmazingFeature)
|
||||
- Ă–ffnen Sie einen Pull Request
|
||||
|
||||
## Support
|
||||
|
||||
Bei Fragen zum *Messaging Service* und dessen *Verträgen* kontaktieren Sie bitte das [LINK Mobility Team](https://www.linkmobility.de/kontakt).
|
||||
|
||||
Zu *technischen Anfragen* finden Sie die Kontaktmöglichkeiten in der [composer.json](composer.json).
|
||||
|
||||
## Lizenz
|
||||
(Stand: 13.07.2022)
|
||||
|
||||
|
@ -96,7 +96,7 @@ 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()],
|
||||
];
|
||||
}
|
||||
|
||||
@ -167,7 +167,7 @@ class ClientTest extends ApiTestCase
|
||||
{
|
||||
return [
|
||||
'request is valid' => [true],
|
||||
'request is not valid' => [false]
|
||||
'request is not valid' => [false],
|
||||
];
|
||||
}
|
||||
|
||||
@ -203,7 +203,7 @@ class ClientTest extends ApiTestCase
|
||||
'withHeader',
|
||||
'withAddedHeader',
|
||||
'withoutHeader',
|
||||
'withBody'
|
||||
'withBody',
|
||||
])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
@ -232,7 +232,7 @@ class ClientTest extends ApiTestCase
|
||||
$clientMock = $this->getMockBuilder(Client::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods([
|
||||
'getLoggerHandler'
|
||||
'getLoggerHandler',
|
||||
])
|
||||
->getMock();
|
||||
$clientMock->expects($this->atLeastOnce())
|
||||
|
@ -50,7 +50,7 @@ class RecipientsListTest extends ApiTestCase
|
||||
|
||||
$phoneUtil = PhoneNumberUtil::getInstance();
|
||||
$example = $phoneUtil->getExampleNumberForType($this->phoneCountryFixture, PhoneNumberType::MOBILE);
|
||||
$this->phoneNumberFixture = $phoneUtil->format($example, PhoneNumberFormat::NATIONAL);
|
||||
$this->phoneNumberFixture = $phoneUtil->format($example, PhoneNumberFormat::NATIONAL);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -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(
|
||||
|
@ -17,6 +17,7 @@ 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;
|
||||
@ -24,6 +25,7 @@ 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;
|
||||
@ -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('setClient')->with($this->equalTo($clientMock))->willReturnSelf();
|
||||
|
||||
$this->assertInstanceOf(
|
||||
Request::class,
|
||||
$this->callMethod(
|
||||
$requestMock,
|
||||
'__construct',
|
||||
[$messageMock, $clientMock]
|
||||
)
|
||||
$this->callMethod(
|
||||
$requestMock,
|
||||
'__construct',
|
||||
[$messageMock, $clientMock]
|
||||
);
|
||||
}
|
||||
|
||||
@ -115,16 +114,19 @@ 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()
|
||||
{
|
||||
$phoneUtil = PhoneNumberUtil::getInstance();
|
||||
$example = $phoneUtil->getExampleNumberForType('DE', PhoneNumberType::MOBILE);
|
||||
$phoneNumberFixture = $phoneUtil->format($example, PhoneNumberFormat::NATIONAL);
|
||||
$phoneNumberFixture = $phoneUtil->format($example, PhoneNumberFormat::NATIONAL);
|
||||
|
||||
$recipient = new Recipient($phoneNumberFixture, 'DE');
|
||||
|
||||
@ -149,15 +151,18 @@ 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()
|
||||
{
|
||||
$phoneUtil = PhoneNumberUtil::getInstance();
|
||||
$example = $phoneUtil->getExampleNumberForType('DE', PhoneNumberType::MOBILE);
|
||||
$phoneNumberFixture = $phoneUtil->format($example, PhoneNumberFormat::NATIONAL);
|
||||
$phoneNumberFixture = $phoneUtil->format($example, PhoneNumberFormat::NATIONAL);
|
||||
|
||||
$recipient = new Recipient($phoneNumberFixture, 'DE');
|
||||
|
||||
@ -253,17 +258,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,
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@ -284,20 +289,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'
|
||||
@ -671,7 +676,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('{}');
|
||||
|
||||
@ -680,12 +685,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],
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -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 $response */
|
||||
/** @var Response|MockObject $responseMock */
|
||||
$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'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -100,8 +100,8 @@ class RequestFactoryTest extends ApiTestCase
|
||||
public function getTextSmsRequestDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'binary' => [RequestFactory::GSM_UCS2, BinaryRequest::class],
|
||||
'ascii' => [RequestFactory::GSM_7BIT, TextRequest::class]
|
||||
'binary' => [SmsLength::ENCODING_UCS2, BinaryRequest::class],
|
||||
'ascii' => [SmsLength::ENCODING_7BIT, TextRequest::class],
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ class RecipientTest extends ApiTestCase
|
||||
|
||||
$phoneUtil = PhoneNumberUtil::getInstance();
|
||||
$example = $phoneUtil->getExampleNumberForType($this->phoneCountryFixture, PhoneNumberType::MOBILE);
|
||||
$this->phoneNumberFixture = $phoneUtil->format($example, PhoneNumberFormat::NATIONAL);
|
||||
$this->phoneNumberFixture = $phoneUtil->format($example, PhoneNumberFormat::NATIONAL);
|
||||
|
||||
$this->recipient = new Recipient($this->phoneNumberFixture, $this->phoneCountryFixture);
|
||||
}
|
||||
@ -149,20 +149,20 @@ class RecipientTest extends ApiTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[][]
|
||||
* @return array[]
|
||||
*/
|
||||
public function constructInvalidDataProvider(): array
|
||||
{
|
||||
$phoneUtil = PhoneNumberUtil::getInstance();
|
||||
$example = $phoneUtil->getExampleNumberForType($this->phoneCountryFixture, PhoneNumberType::MOBILE);
|
||||
$phoneNumberFixture = $phoneUtil->format($example, PhoneNumberFormat::NATIONAL);
|
||||
$phoneNumberFixture = $phoneUtil->format($example, PhoneNumberFormat::NATIONAL);
|
||||
|
||||
return [
|
||||
'empty number' => ['', 'DE', true, PhoneNumberType::MOBILE, InvalidArgumentException::class],
|
||||
'invalid country code' => [$phoneNumberFixture, 'DEX', true, PhoneNumberType::MOBILE, InvalidArgumentException::class],
|
||||
'unparsable' => ['abc', 'DE', true, PhoneNumberType::MOBILE, NumberParseException::class],
|
||||
'invalid number' => ['abcd', 'DE', false, PhoneNumberType::MOBILE, RecipientException::class],
|
||||
'not mobile number' => ['abcd', 'DE', false, 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;
|
||||
|
||||
use Assert\InvalidArgumentException;
|
||||
use D3\LinkmobilityClient\Exceptions\NoSenderDefinedException;
|
||||
use D3\LinkmobilityClient\Exceptions\RecipientException;
|
||||
use D3\LinkmobilityClient\Tests\ApiTestCase;
|
||||
use D3\LinkmobilityClient\ValueObject\Sender;
|
||||
@ -30,7 +29,7 @@ use ReflectionException;
|
||||
|
||||
class SenderTest extends ApiTestCase
|
||||
{
|
||||
/** @var Sender */
|
||||
/** @var Sender|MockObject */
|
||||
public $sender;
|
||||
|
||||
private $phoneNumberFixture;
|
||||
@ -47,9 +46,8 @@ class SenderTest extends ApiTestCase
|
||||
|
||||
$phoneUtil = PhoneNumberUtil::getInstance();
|
||||
$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);
|
||||
}
|
||||
|
||||
@ -107,12 +105,12 @@ class SenderTest extends ApiTestCase
|
||||
{
|
||||
$phoneUtil = PhoneNumberUtil::getInstance();
|
||||
$example = $phoneUtil->getExampleNumberForType($this->phoneCountryFixture, PhoneNumberType::MOBILE);
|
||||
$this->phoneNumberFixture = $phoneUtil->format($example, PhoneNumberFormat::NATIONAL);
|
||||
$this->phoneNumberFixture = $phoneUtil->format($example, PhoneNumberFormat::NATIONAL);
|
||||
|
||||
return [
|
||||
'null number' => [null, $this->phoneCountryFixture, false],
|
||||
'null country' => [$this->phoneNumberFixture, null, false],
|
||||
'all values' => [$this->phoneNumberFixture, $this->phoneCountryFixture, true]
|
||||
'all values' => [$this->phoneNumberFixture, $this->phoneCountryFixture, true],
|
||||
];
|
||||
}
|
||||
|
||||
@ -122,11 +120,9 @@ class SenderTest extends ApiTestCase
|
||||
* @param $country
|
||||
* @param $validNumber
|
||||
* @param $expectedException
|
||||
*
|
||||
* @throws NumberParseException
|
||||
* @throws RecipientException
|
||||
* @throws ReflectionException
|
||||
* @dataProvider constructInvalidDataProvider
|
||||
* @covers \D3\LinkmobilityClient\ValueObject\Sender::__construct
|
||||
* @covers \D3\LinkmobilityClient\ValueObject\Sender::__construct
|
||||
*/
|
||||
public function testConstructInvalid($number, $country, $validNumber, $expectedException)
|
||||
{
|
||||
@ -162,19 +158,19 @@ class SenderTest extends ApiTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[][]
|
||||
* @return array[]
|
||||
*/
|
||||
public function constructInvalidDataProvider(): array
|
||||
{
|
||||
$phoneUtil = PhoneNumberUtil::getInstance();
|
||||
$example = $phoneUtil->getExampleNumberForType($this->phoneCountryFixture, PhoneNumberType::MOBILE);
|
||||
$phoneNumberFixture = $phoneUtil->format($example, PhoneNumberFormat::NATIONAL);
|
||||
$phoneNumberFixture = $phoneUtil->format($example, PhoneNumberFormat::NATIONAL);
|
||||
|
||||
return [
|
||||
'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],
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@ use Phlib\SmsLength\SmsLength;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use ReflectionException;
|
||||
|
||||
class SmsBinaryMessageTest extends ApiTestCase
|
||||
class SmsBinaryMessageTest extends SmsMessageAbstractTest
|
||||
{
|
||||
/** @var SmsBinaryMessage */
|
||||
public $message;
|
||||
@ -39,21 +39,12 @@ class SmsBinaryMessageTest extends ApiTestCase
|
||||
$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()
|
||||
{
|
||||
@ -91,6 +82,7 @@ class SmsBinaryMessageTest extends ApiTestCase
|
||||
* @throws ReflectionException
|
||||
* @dataProvider constructInvalidDataProvider
|
||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsBinaryMessage::__construct
|
||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsMessageAbstract::__construct
|
||||
*/
|
||||
public function testConstructInvalid($binaryMessage, $valid, $expectedException)
|
||||
{
|
||||
@ -124,37 +116,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
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsBinaryMessage::chunkCount
|
||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsMessageAbstract::chunkCount
|
||||
*/
|
||||
public function testGetChunkCount()
|
||||
{
|
||||
@ -170,9 +136,9 @@ class SmsBinaryMessageTest extends ApiTestCase
|
||||
|
||||
/** @var SmsBinaryMessage|MockObject $message */
|
||||
$message = $this->getMockBuilder(SmsBinaryMessage::class)
|
||||
->onlyMethods(['getSmsLength'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
->onlyMethods(['getSmsLength'])
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$message->method('getSmsLength')->willReturn($smsLengthMock);
|
||||
|
||||
$this->assertSame(
|
||||
@ -188,6 +154,7 @@ class SmsBinaryMessageTest extends ApiTestCase
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsBinaryMessage::length
|
||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsMessageAbstract::length
|
||||
*/
|
||||
public function testGetSize()
|
||||
{
|
||||
|
66
Tests/ValueObject/SmsMessageAbstractTest.php
Normal file
66
Tests/ValueObject/SmsMessageAbstractTest.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?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 PHPUnit\Framework\MockObject\MockObject;
|
||||
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 ReflectionException;
|
||||
|
||||
class SmsTextMessageTest extends SmsBinaryMessageTest
|
||||
class SmsTextMessageTest extends SmsMessageAbstractTest
|
||||
{
|
||||
/** @var SmsTextMessage */
|
||||
public $message;
|
||||
@ -43,6 +43,7 @@ class SmsTextMessageTest extends SmsBinaryMessageTest
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsTextMessage::__construct
|
||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsMessageAbstract::__construct
|
||||
*/
|
||||
public function testConstructValid()
|
||||
{
|
||||
@ -80,6 +81,7 @@ class SmsTextMessageTest extends SmsBinaryMessageTest
|
||||
* @throws ReflectionException
|
||||
* @dataProvider constructInvalidDataProvider
|
||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsTextMessage::__construct
|
||||
* @covers \D3\LinkmobilityClient\ValueObject\SmsMessageAbstract::__construct
|
||||
*/
|
||||
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;
|
||||
|
||||
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;
|
||||
@ -31,11 +26,13 @@ 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();
|
||||
@ -52,7 +49,7 @@ class ValueObjectTest extends ApiTestCase
|
||||
{
|
||||
$phoneUtil = PhoneNumberUtil::getInstance();
|
||||
$example = $phoneUtil->getExampleNumberForType('DE', PhoneNumberType::MOBILE);
|
||||
$phoneNumberFixture = $phoneUtil->format($example, PhoneNumberFormat::NATIONAL);
|
||||
$phoneNumberFixture = $phoneUtil->format($example, PhoneNumberFormat::NATIONAL);
|
||||
|
||||
$this->callMethod(
|
||||
$this->value,
|
||||
@ -85,4 +82,4 @@ class ValueObjectTest extends ApiTestCase
|
||||
['']
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "d3/linkmobility-php-client",
|
||||
"type": "library",
|
||||
"description": "PHP client for LINK Mobility Austria API",
|
||||
"description": "PHP client for LINK Mobility API",
|
||||
"keywords": [
|
||||
"LINK Mobility",
|
||||
"php",
|
||||
@ -21,18 +21,19 @@
|
||||
"GPL-3.0-or-later"
|
||||
],
|
||||
"require": {
|
||||
"php": "^7.0 || ^8.0",
|
||||
"beberlei/assert": "^2.9.9",
|
||||
"guzzlehttp/guzzle": "~6.2 || ^7.4",
|
||||
"php": "^7.3 || ~8.0.3",
|
||||
"beberlei/assert": "^3.3",
|
||||
"guzzlehttp/guzzle": "^7.4",
|
||||
"psr/http-message": "~1.0",
|
||||
"phlib/sms-length": "^1.1.0 || ^2.0.0",
|
||||
"phlib/sms-length": "^2.0",
|
||||
"giggsey/libphonenumber-for-php": "^8.12.50",
|
||||
"ext-json": "*"
|
||||
},
|
||||
"require-dev": {
|
||||
"php": "^7.2",
|
||||
"phpunit/phpunit" : "^8.0",
|
||||
"friendsofphp/php-cs-fixer": "^2.0"
|
||||
"php": "^7.4 || ~8.0.3",
|
||||
"phpunit/phpunit" : "^9.5",
|
||||
"friendsofphp/php-cs-fixer": "^3.9",
|
||||
"phpstan/phpstan": "^1.8"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
@ -41,8 +42,9 @@
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"test": "phpunit",
|
||||
"test": "./vendor/bin/phpunit",
|
||||
"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 @@
|
||||
|
||||
<phpunit
|
||||
bootstrap="vendor/autoload.php"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true">
|
||||
|
||||
<testsuite name="linkmobility">
|
||||
<directory>./Tests</directory>
|
||||
</testsuite>
|
||||
|
||||
<filter>
|
||||
<whitelist>
|
||||
<directory suffix=".php">src</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
|
||||
<logging>
|
||||
<log type="coverage-clover" target="build/logs/clover.xml"/>
|
||||
</logging>
|
||||
|
||||
<?xml version="1.0"?>
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
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>
|
||||
<testsuite name="linkmobility">
|
||||
<directory>./Tests</directory>
|
||||
</testsuite>
|
||||
<logging/>
|
||||
</phpunit>
|
||||
|
@ -20,10 +20,14 @@ use Psr\Log\NullLogger;
|
||||
|
||||
class LoggerHandler
|
||||
{
|
||||
/** @var LoggerHandler */
|
||||
private static $instance = null;
|
||||
private $logger;
|
||||
|
||||
public static function getInstance()
|
||||
/**
|
||||
* @return LoggerHandler
|
||||
*/
|
||||
public static function getInstance(): LoggerHandler
|
||||
{
|
||||
if (self::$instance === null) {
|
||||
self::$instance = new self();
|
||||
@ -38,7 +42,7 @@ class LoggerHandler
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $logger
|
||||
* @param LoggerInterface $logger
|
||||
*/
|
||||
public function setLogger(LoggerInterface $logger)
|
||||
{
|
||||
|
@ -107,7 +107,7 @@ abstract class Request implements RequestInterface
|
||||
private $test = false;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
* @var int
|
||||
*/
|
||||
private $maxSmsPerMessage = 0;
|
||||
|
||||
@ -119,8 +119,6 @@ abstract class Request implements RequestInterface
|
||||
$this->recipientsList = new RecipientsList($client);
|
||||
$this->setMessage($message);
|
||||
$this->setClient($client);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -169,7 +167,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(),
|
||||
];
|
||||
}
|
||||
|
||||
@ -200,18 +198,18 @@ abstract class Request implements RequestInterface
|
||||
'headers' => [
|
||||
'Accept' => $this->contentType,
|
||||
'Content-Type' => $this->contentType,
|
||||
]
|
||||
],
|
||||
],
|
||||
$this->getBody()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param StringValueObject $message
|
||||
* @param SmsMessageInterface $message
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setMessage(StringValueObject $message): Request
|
||||
public function setMessage(SmsMessageInterface $message): Request
|
||||
{
|
||||
$this->message = $message;
|
||||
|
||||
@ -280,7 +278,7 @@ abstract class Request implements RequestInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getClientMessageId()
|
||||
public function getClientMessageId(): ?string
|
||||
{
|
||||
return $this->clientMessageId;
|
||||
}
|
||||
@ -306,7 +304,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,
|
||||
];
|
||||
}
|
||||
|
||||
@ -376,7 +374,7 @@ abstract class Request implements RequestInterface
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getNotificationCallbackUrl()
|
||||
public function getNotificationCallbackUrl(): ?string
|
||||
{
|
||||
return $this->notificationCallbackUrl;
|
||||
}
|
||||
@ -396,7 +394,7 @@ abstract class Request implements RequestInterface
|
||||
/**
|
||||
* @return int|null
|
||||
*/
|
||||
public function getPriority()
|
||||
public function getPriority(): ?int
|
||||
{
|
||||
return $this->priority;
|
||||
}
|
||||
@ -422,7 +420,7 @@ abstract class Request implements RequestInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool|null
|
||||
* @return bool
|
||||
*/
|
||||
public function doSendAsFlashSms(): bool
|
||||
{
|
||||
@ -444,7 +442,7 @@ abstract class Request implements RequestInterface
|
||||
/**
|
||||
* @return Sender|null
|
||||
*/
|
||||
public function getSenderAddress()
|
||||
public function getSenderAddress(): ?Sender
|
||||
{
|
||||
return $this->senderAddress;
|
||||
}
|
||||
@ -464,7 +462,7 @@ abstract class Request implements RequestInterface
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getSenderAddressType()
|
||||
public function getSenderAddressType(): ?string
|
||||
{
|
||||
return $this->getSenderAddress() && $this->getSenderAddress()->get() ? $this->senderAddressType : null;
|
||||
}
|
||||
@ -478,7 +476,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,
|
||||
];
|
||||
}
|
||||
|
||||
@ -497,7 +495,7 @@ abstract class Request implements RequestInterface
|
||||
/**
|
||||
* @return int|null
|
||||
*/
|
||||
public function getValidityPeriode()
|
||||
public function getValidityPeriode(): ?int
|
||||
{
|
||||
return $this->validityPeriode;
|
||||
}
|
||||
@ -523,6 +521,7 @@ abstract class Request implements RequestInterface
|
||||
|
||||
/**
|
||||
* @param Client $client
|
||||
* @return Request
|
||||
*/
|
||||
public function setClient(Client $client): Request
|
||||
{
|
||||
|
@ -16,6 +16,7 @@ declare(strict_types=1);
|
||||
namespace D3\LinkmobilityClient\Request;
|
||||
|
||||
use D3\LinkmobilityClient\Client;
|
||||
use D3\LinkmobilityClient\RecipientsList\RecipientsListInterface;
|
||||
use D3\LinkmobilityClient\ValueObject\SmsMessageInterface;
|
||||
use InvalidArgumentException;
|
||||
use Psr\Http\Message\ResponseInterface as PsrResponseInterface;
|
||||
@ -42,9 +43,18 @@ interface RequestInterface
|
||||
public const SENDERADDRESSTYPE_ALPHANUMERIC = 'alphanumeric';
|
||||
public const SENDERADDRESSTYPE_SHORTCODE = 'shortcode';
|
||||
|
||||
/**
|
||||
* @param SmsMessageInterface $message
|
||||
* @param Client $client
|
||||
*/
|
||||
public function __construct(SmsMessageInterface $message, Client $client);
|
||||
|
||||
public function setMethod(string $method);
|
||||
/**
|
||||
* @param string $method
|
||||
*
|
||||
* @return Request
|
||||
*/
|
||||
public function setMethod(string $method): Request;
|
||||
|
||||
/**
|
||||
* Must return the HTTP verb for this request, i.e. GET, POST, PUT
|
||||
@ -53,6 +63,18 @@ interface RequestInterface
|
||||
*/
|
||||
public function getMethod(): string;
|
||||
|
||||
/**
|
||||
* @param bool $test
|
||||
*
|
||||
* @return Request
|
||||
*/
|
||||
public function setTestMode(bool $test): Request;
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function getTestMode(): bool;
|
||||
|
||||
/**
|
||||
* Must return the URI for the request with a leading slash, i.e. /messages.json
|
||||
*
|
||||
@ -81,6 +103,11 @@ interface RequestInterface
|
||||
*/
|
||||
public function getResponseInstance(PsrResponseInterface $rawResponse): LMResponseInterface;
|
||||
|
||||
/**
|
||||
* @return RecipientsListInterface
|
||||
*/
|
||||
public function getRecipientsList(): RecipientsListInterface;
|
||||
|
||||
/**
|
||||
* Must return the options for this request. If there are none, return [] (empty array)
|
||||
*
|
||||
|
@ -72,7 +72,7 @@ abstract class Response implements ResponseInterface
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getClientMessageId()
|
||||
public function getClientMessageId(): ?string
|
||||
{
|
||||
return $this->getContent()[self::CLIENTMESSAGEID];
|
||||
}
|
||||
@ -80,13 +80,13 @@ abstract class Response implements ResponseInterface
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getTransferId()
|
||||
public function getTransferId(): ?string
|
||||
{
|
||||
return $this->getContent()[self::TRANSFERID];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
* @return int
|
||||
*/
|
||||
public function getSmsCount(): int
|
||||
{
|
||||
|
@ -36,7 +36,7 @@ class BinaryRequest extends Request implements SmsRequestInterface
|
||||
return array_merge(
|
||||
parent::getRawBody(),
|
||||
[
|
||||
'userDataHeaderPresent' => true
|
||||
'userDataHeaderPresent' => true,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
@ -20,21 +20,15 @@ use D3\LinkmobilityClient\ValueObject\SmsBinaryMessage;
|
||||
use D3\LinkmobilityClient\ValueObject\SmsTextMessage;
|
||||
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 $client;
|
||||
|
||||
/**
|
||||
* @param $message
|
||||
* @param Client $client
|
||||
*/
|
||||
public function __construct($message, Client $client)
|
||||
{
|
||||
$this->message = $message;
|
||||
@ -46,7 +40,7 @@ class RequestFactory
|
||||
*/
|
||||
public function getSmsRequest(): SmsRequestInterface
|
||||
{
|
||||
if ($this->getSmsLength()->getEncoding() === self::GSM_7BIT) {
|
||||
if ($this->getSmsLength()->getEncoding() === SmsLength::ENCODING_7BIT) {
|
||||
$message = new SmsTextMessage($this->message);
|
||||
return new TextRequest($message, $this->client);
|
||||
}
|
||||
|
@ -15,9 +15,11 @@ declare(strict_types=1);
|
||||
|
||||
namespace D3\LinkmobilityClient\SMS;
|
||||
|
||||
use D3\LinkmobilityClient\Client;
|
||||
|
||||
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;
|
||||
|
||||
class Response extends \D3\LinkmobilityClient\Response\Response
|
||||
use D3\LinkmobilityClient\Response\Response as BaseResponse;
|
||||
|
||||
class Response extends BaseResponse
|
||||
{
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ class Url implements UrlInterface
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTextSmsUri()
|
||||
public function getTextSmsUri(): string
|
||||
{
|
||||
return '/rest/smsmessaging/text';
|
||||
}
|
||||
@ -38,7 +38,7 @@ class Url implements UrlInterface
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getBinarySmsUri()
|
||||
public function getBinarySmsUri(): string
|
||||
{
|
||||
return '/rest/smsmessaging/binary';
|
||||
}
|
||||
|
@ -18,4 +18,8 @@ namespace D3\LinkmobilityClient\Url;
|
||||
interface UrlInterface
|
||||
{
|
||||
public function getBaseUri(): string;
|
||||
|
||||
public function getTextSmsUri(): string;
|
||||
|
||||
public function getBinarySmsUri(): string;
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ class Recipient extends StringValueObject
|
||||
*/
|
||||
protected $allowedNumberTypes = [
|
||||
PhoneNumberType::MOBILE,
|
||||
PhoneNumberType::FIXED_LINE_OR_MOBILE
|
||||
PhoneNumberType::FIXED_LINE_OR_MOBILE,
|
||||
];
|
||||
|
||||
/**
|
||||
@ -53,7 +53,7 @@ class Recipient extends StringValueObject
|
||||
$phoneUtil = $this->getPhoneNumberUtil();
|
||||
|
||||
$phoneNumber = $phoneUtil->parse($number, strtoupper($iso2CountryCode));
|
||||
$number = $phoneUtil->format( $phoneNumber, PhoneNumberFormat::E164 );
|
||||
$number = $phoneUtil->format($phoneNumber, PhoneNumberFormat::E164);
|
||||
|
||||
if (false === $phoneUtil->isValidNumber($phoneNumber)) {
|
||||
throw new RecipientException(ExceptionMessages::INVALID_RECIPIENT_PHONE);
|
||||
@ -63,9 +63,9 @@ class Recipient extends StringValueObject
|
||||
$this->allowedNumberTypes
|
||||
)
|
||||
) {
|
||||
throw new RecipientException( ExceptionMessages::NOT_A_MOBILE_NUMBER);
|
||||
throw new RecipientException(ExceptionMessages::NOT_A_MOBILE_NUMBER);
|
||||
}
|
||||
|
||||
|
||||
parent::__construct($number);
|
||||
$this->countryCode = $iso2CountryCode;
|
||||
}
|
||||
@ -86,7 +86,7 @@ class Recipient extends StringValueObject
|
||||
return $this->countryCode;
|
||||
}
|
||||
|
||||
public function getFormatted()
|
||||
public function getFormatted(): string
|
||||
{
|
||||
return ltrim(parent::getFormatted(), '+');
|
||||
}
|
||||
|
@ -27,11 +27,11 @@ use libphonenumber\PhoneNumberUtil;
|
||||
class Sender extends ValueObject
|
||||
{
|
||||
/**
|
||||
* @param string $number
|
||||
* @param string $iso2CountryCode
|
||||
* @param string|null $number
|
||||
* @param string|null $iso2CountryCode
|
||||
*
|
||||
* @throws RecipientException
|
||||
* @throws NumberParseException
|
||||
* @throws RecipientException
|
||||
*/
|
||||
public function __construct(string $number = null, string $iso2CountryCode = null)
|
||||
{
|
||||
@ -67,7 +67,7 @@ class Sender extends ValueObject
|
||||
return PhoneNumberUtil::getInstance();
|
||||
}
|
||||
|
||||
public function getFormatted()
|
||||
public function getFormatted(): string
|
||||
{
|
||||
return ltrim(parent::getFormatted(), '+');
|
||||
}
|
||||
|
@ -43,6 +43,9 @@ abstract class SmsMessageAbstract extends StringValueObject implements SmsMessag
|
||||
return $this->getSmsLength()->getSize();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getMessageContent()
|
||||
{
|
||||
return $this->get();
|
||||
|
@ -15,8 +15,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace D3\LinkmobilityClient\ValueObject;
|
||||
|
||||
use Assert\Assert;
|
||||
|
||||
abstract class StringValueObject extends ValueObject
|
||||
{
|
||||
public function __toString()
|
||||
|
@ -33,7 +33,7 @@ abstract class ValueObject
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
public function getFormatted()
|
||||
public function getFormatted(): string
|
||||
{
|
||||
return $this->get();
|
||||
}
|
||||
|
Reference in New Issue
Block a user