From 23de1d2f0684a28a5037510bce6b38919ee5f9e7 Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Fri, 15 Jul 2022 16:16:07 +0200 Subject: [PATCH] fix special phone number format before the request to be able to perform external checks with valid content --- Tests/ClientTest.php | 2 +- Tests/ValueObject/RecipientTest.php | 2 +- src/RecipientsList/RecipientsList.php | 5 ++++- src/ValueObject/Recipient.php | 7 ++++++- src/ValueObject/Sender.php | 7 ++++++- 5 files changed, 18 insertions(+), 5 deletions(-) diff --git a/Tests/ClientTest.php b/Tests/ClientTest.php index 0e6f06c..63b5c9a 100644 --- a/Tests/ClientTest.php +++ b/Tests/ClientTest.php @@ -205,7 +205,7 @@ class ClientTest extends ApiTestCase ->disableOriginalConstructor() ->getMock(); $responseMock->expects($this->atLeastOnce())->method('getStatusCode')->willReturn($statusCode); - $responseMock->expects($okStatus ? $this->atLeastOnce() : $this->never()) + $responseMock->expects($this->atLeastOnce()) ->method('getBody')->willReturn($streamMock); /** @var GuzzleClient|MockObject $requestClientMock */ diff --git a/Tests/ValueObject/RecipientTest.php b/Tests/ValueObject/RecipientTest.php index c6670a6..b3611e9 100644 --- a/Tests/ValueObject/RecipientTest.php +++ b/Tests/ValueObject/RecipientTest.php @@ -78,7 +78,7 @@ class RecipientTest extends ApiTestCase $recipientMock->__construct($this->phoneNumberFixture, $this->phoneCountryFixture); $this->assertSame( - '491527565839', + '+491527565839', $this->callMethod( $recipientMock, 'get' diff --git a/src/RecipientsList/RecipientsList.php b/src/RecipientsList/RecipientsList.php index e6fcfa6..d7992b9 100644 --- a/src/RecipientsList/RecipientsList.php +++ b/src/RecipientsList/RecipientsList.php @@ -94,12 +94,15 @@ class RecipientsList implements RecipientsListInterface, Iterator return $this; } + /** + * @return array + */ public function getRecipients(): array { return array_values( array_map( function (Recipient $recipient) { - return $recipient->get(); + return $recipient->getFormatted(); }, $this->recipients ) diff --git a/src/ValueObject/Recipient.php b/src/ValueObject/Recipient.php index 05b876d..55d9eba 100644 --- a/src/ValueObject/Recipient.php +++ b/src/ValueObject/Recipient.php @@ -40,7 +40,7 @@ class Recipient extends StringValueObject $phoneUtil = $this->getPhoneNumberUtil(); $phoneNumber = $phoneUtil->parse($number, strtoupper($iso2CountryCode)); - $number = ltrim($phoneUtil->format($phoneNumber, PhoneNumberFormat::E164), '+'); + $number = $phoneUtil->format($phoneNumber, PhoneNumberFormat::E164); parent::__construct($number); $this->countryCode = $iso2CountryCode; @@ -61,4 +61,9 @@ class Recipient extends StringValueObject { return $this->countryCode; } + + public function getFormatted() + { + return ltrim(parent::getFormatted(), '+'); + } } diff --git a/src/ValueObject/Sender.php b/src/ValueObject/Sender.php index cec7896..a84c979 100644 --- a/src/ValueObject/Sender.php +++ b/src/ValueObject/Sender.php @@ -45,7 +45,7 @@ class Sender extends ValueObject $phoneUtil = $this->getPhoneNumberUtil(); $phoneNumber = $phoneUtil->parse($number, strtoupper($iso2CountryCode)); - $number = ltrim($phoneUtil->format($phoneNumber, PhoneNumberFormat::E164), '+'); + $number = $phoneUtil->format($phoneNumber, PhoneNumberFormat::E164); if (false === $phoneUtil->isValidNumber($phoneNumber)) { throw new RecipientException(ExceptionMessages::INVALID_SENDER); @@ -66,4 +66,9 @@ class Sender extends ValueObject { return PhoneNumberUtil::getInstance(); } + + public function getFormatted() + { + return ltrim(parent::getFormatted(), '+'); + } }