adjust to current dependency packages and PHP >= 7.3

This commit is contained in:
Daniel Seifert 2022-07-19 23:20:33 +02:00 committed by Daniel Seifert
parent b22da1bd4a
commit 7e43fa1537
Signed by: DanielS
GPG Key ID: 8A7C4C6ED1915C6F
27 changed files with 122 additions and 114 deletions

View File

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

View File

@ -2,6 +2,12 @@
---
## 2.0.0.0 (2022-07-19)
- adjust to PHP >= 7.3 and current dependency packages
---
## 1.3.0.0 (2022-07-18)
- tests use generated example phone numbers

View File

@ -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())

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,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;
@ -115,10 +117,13 @@ 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()
{
@ -149,9 +154,12 @@ 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()
{
@ -253,17 +261,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 +292,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 +679,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 +688,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);
@ -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' => [RequestFactory::GSM_UCS2, BinaryRequest::class],
'ascii' => [RequestFactory::GSM_7BIT, TextRequest::class]
'binary' => [SmsLength::ENCODING_UCS2, BinaryRequest::class],
'ascii' => [SmsLength::ENCODING_7BIT, TextRequest::class],
];
}

View File

@ -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,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;
@ -112,7 +111,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],
];
}
@ -122,11 +121,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)
{
@ -174,7 +171,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

@ -131,7 +131,7 @@ class SmsBinaryMessageTest extends ApiTestCase
{
return [
'empty message' => ['', true, InvalidArgumentException::class],
'invalid sms message' => ['abc', false, \Phlib\SmsLength\Exception\InvalidArgumentException::class]
'invalid sms message' => ['abc', false, \Phlib\SmsLength\Exception\InvalidArgumentException::class],
];
}

View File

@ -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;

View File

@ -21,18 +21,18 @@
"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",
"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",
"phpunit/phpunit" : "^9.5",
"friendsofphp/php-cs-fixer": "^3.9"
},
"autoload": {
"psr-4": {

View File

@ -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>

View File

@ -23,7 +23,7 @@ class LoggerHandler
private static $instance = null;
private $logger;
public static function getInstance()
public static function getInstance(): ?LoggerHandler
{
if (self::$instance === null) {
self::$instance = new self();

View File

@ -169,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(),
];
}
@ -200,7 +200,7 @@ abstract class Request implements RequestInterface
'headers' => [
'Accept' => $this->contentType,
'Content-Type' => $this->contentType,
]
],
],
$this->getBody()
);
@ -280,7 +280,7 @@ abstract class Request implements RequestInterface
return $this;
}
public function getClientMessageId()
public function getClientMessageId(): ?string
{
return $this->clientMessageId;
}
@ -306,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,
];
}
@ -376,7 +376,7 @@ abstract class Request implements RequestInterface
/**
* @return string|null
*/
public function getNotificationCallbackUrl()
public function getNotificationCallbackUrl(): ?string
{
return $this->notificationCallbackUrl;
}
@ -396,7 +396,7 @@ abstract class Request implements RequestInterface
/**
* @return int|null
*/
public function getPriority()
public function getPriority(): ?int
{
return $this->priority;
}
@ -444,7 +444,7 @@ abstract class Request implements RequestInterface
/**
* @return Sender|null
*/
public function getSenderAddress()
public function getSenderAddress(): ?Sender
{
return $this->senderAddress;
}
@ -464,7 +464,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 +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,
];
}
@ -497,7 +497,7 @@ abstract class Request implements RequestInterface
/**
* @return int|null
*/
public function getValidityPeriode()
public function getValidityPeriode(): ?int
{
return $this->validityPeriode;
}
@ -523,6 +523,7 @@ abstract class Request implements RequestInterface
/**
* @param Client $client
* @return Request
*/
public function setClient(Client $client): Request
{

View File

@ -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
{

View File

@ -36,7 +36,7 @@ class BinaryRequest extends Request implements SmsRequestInterface
return array_merge(
parent::getRawBody(),
[
'userDataHeaderPresent' => true
'userDataHeaderPresent' => true,
]
);
}

View File

@ -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);
}

View File

@ -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;
}

View File

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

View File

@ -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';
}

View File

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

View File

@ -30,7 +30,7 @@ class Recipient extends StringValueObject
*/
protected $allowedNumberTypes = [
PhoneNumberType::MOBILE,
PhoneNumberType::FIXED_LINE_OR_MOBILE
PhoneNumberType::FIXED_LINE_OR_MOBILE,
];
/**
@ -86,7 +86,7 @@ class Recipient extends StringValueObject
return $this->countryCode;
}
public function getFormatted()
public function getFormatted(): string
{
return ltrim(parent::getFormatted(), '+');
}

View File

@ -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(), '+');
}

View File

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

View File

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

View File

@ -33,7 +33,7 @@ abstract class ValueObject
return $this->value;
}
public function getFormatted()
public function getFormatted(): string
{
return $this->get();
}