fix special phone number format before the request to be able to perform external checks with valid content

This commit is contained in:
Daniel Seifert 2022-07-15 16:16:07 +02:00
parent 73694a1c57
commit 23de1d2f06
Signed by: DanielS
GPG Key ID: 8A7C4C6ED1915C6F
5 changed files with 18 additions and 5 deletions

View File

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

View File

@ -78,7 +78,7 @@ class RecipientTest extends ApiTestCase
$recipientMock->__construct($this->phoneNumberFixture, $this->phoneCountryFixture);
$this->assertSame(
'491527565839',
'+491527565839',
$this->callMethod(
$recipientMock,
'get'

View File

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

View File

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

View File

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