Compare commits

...

2 Commits
1.2.0 ... 1.2.1

6 changed files with 23 additions and 9 deletions

View File

@ -205,7 +205,7 @@ class ClientTest extends ApiTestCase
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$responseMock->expects($this->atLeastOnce())->method('getStatusCode')->willReturn($statusCode); $responseMock->expects($this->atLeastOnce())->method('getStatusCode')->willReturn($statusCode);
$responseMock->expects($okStatus ? $this->atLeastOnce() : $this->never()) $responseMock->expects($this->atLeastOnce())
->method('getBody')->willReturn($streamMock); ->method('getBody')->willReturn($streamMock);
/** @var GuzzleClient|MockObject $requestClientMock */ /** @var GuzzleClient|MockObject $requestClientMock */

View File

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

View File

@ -68,7 +68,7 @@ class Client
{ {
$options['headers']['Authorization'] = 'Bearer '.$this->accessToken; $options['headers']['Authorization'] = 'Bearer '.$this->accessToken;
$this->getLoggerHandler()->getLogger()->debug('request '.$url, $options); $this->getLoggerHandler()->getLogger()->debug('linkmobility request: '.$url, $options);
$response = $this->requestClient->request( $response = $this->requestClient->request(
$method, $method,
@ -78,7 +78,8 @@ class Client
if ($response->getStatusCode() != 200) { if ($response->getStatusCode() != 200) {
$message = sprintf(ExceptionMessages::NOK_REQUEST_RETURN, $url, $response->getStatusCode()); $message = sprintf(ExceptionMessages::NOK_REQUEST_RETURN, $url, $response->getStatusCode());
$this->getLoggerHandler()->getLogger()->error($message); $response->getBody()->rewind();
$this->getLoggerHandler()->getLogger()->error($message, [$response->getBody()->getContents()]);
throw new ApiException($message); throw new ApiException($message);
} }

View File

@ -76,9 +76,9 @@ class RecipientsList implements RecipientsListInterface, Iterator
$this->recipients[ md5(serialize($recipient)) ] = $recipient; $this->recipients[ md5(serialize($recipient)) ] = $recipient;
} catch (NumberParseException $e) { } catch (NumberParseException $e) {
$this->client->getLoggerHandler()->getLogger()->info($e->getMessage()); $this->client->getLoggerHandler()->getLogger()->info($e->getMessage(), [$recipient]);
} catch (RecipientException $e) { } catch (RecipientException $e) {
$this->client->getLoggerHandler()->getLogger()->info($e->getMessage()); $this->client->getLoggerHandler()->getLogger()->info($e->getMessage(), [$recipient]);
} }
return $this; return $this;
@ -94,12 +94,15 @@ class RecipientsList implements RecipientsListInterface, Iterator
return $this; return $this;
} }
/**
* @return array
*/
public function getRecipients(): array public function getRecipients(): array
{ {
return array_values( return array_values(
array_map( array_map(
function (Recipient $recipient) { function (Recipient $recipient) {
return $recipient->get(); return $recipient->getFormatted();
}, },
$this->recipients $this->recipients
) )

View File

@ -40,7 +40,7 @@ class Recipient extends StringValueObject
$phoneUtil = $this->getPhoneNumberUtil(); $phoneUtil = $this->getPhoneNumberUtil();
$phoneNumber = $phoneUtil->parse($number, strtoupper($iso2CountryCode)); $phoneNumber = $phoneUtil->parse($number, strtoupper($iso2CountryCode));
$number = ltrim($phoneUtil->format($phoneNumber, PhoneNumberFormat::E164), '+'); $number = $phoneUtil->format($phoneNumber, PhoneNumberFormat::E164);
parent::__construct($number); parent::__construct($number);
$this->countryCode = $iso2CountryCode; $this->countryCode = $iso2CountryCode;
@ -61,4 +61,9 @@ class Recipient extends StringValueObject
{ {
return $this->countryCode; return $this->countryCode;
} }
public function getFormatted()
{
return ltrim(parent::getFormatted(), '+');
}
} }

View File

@ -45,7 +45,7 @@ class Sender extends ValueObject
$phoneUtil = $this->getPhoneNumberUtil(); $phoneUtil = $this->getPhoneNumberUtil();
$phoneNumber = $phoneUtil->parse($number, strtoupper($iso2CountryCode)); $phoneNumber = $phoneUtil->parse($number, strtoupper($iso2CountryCode));
$number = ltrim($phoneUtil->format($phoneNumber, PhoneNumberFormat::E164), '+'); $number = $phoneUtil->format($phoneNumber, PhoneNumberFormat::E164);
if (false === $phoneUtil->isValidNumber($phoneNumber)) { if (false === $phoneUtil->isValidNumber($phoneNumber)) {
throw new RecipientException(ExceptionMessages::INVALID_SENDER); throw new RecipientException(ExceptionMessages::INVALID_SENDER);
@ -66,4 +66,9 @@ class Sender extends ValueObject
{ {
return PhoneNumberUtil::getInstance(); return PhoneNumberUtil::getInstance();
} }
public function getFormatted()
{
return ltrim(parent::getFormatted(), '+');
}
} }