8000 bug #58242 [Notifier][TurboSMS] Process partial accepted response fro… · symfony/symfony@28b1709 · GitHub
[go: up one dir, main page]

Skip to content

Commit 28b1709

Browse files
bug #58242 [Notifier][TurboSMS] Process partial accepted response from transport (ZhukV)
This PR was squashed before being merged into the 6.4 branch. Discussion ---------- [Notifier][TurboSMS] Process partial accepted response from transport | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | None | License | MIT TurboSMS can return `null` as message id, if sms not sent to recipient. Example: ```json { "response_code": 802, "response_status": "SUCCESS_MESSAGE_PARTIAL_ACCEPTED", "response_result": [ { "phone": "recipient_1", "response_code": 406, "message_id": null, "response_status": "NOT_ALLOWED_RECIPIENT_COUNTRY" }, { "phone": "recipient_2", "response_code": 0, "message_id": "f83f8868-5e46-c6cf-e4fb-615e5a293754", "response_status": "OK" } ] } ``` And we receive error: ``` Symfony\Component\Notifier\Message\SentMessage::setMessageId(): Argument #1 ($id) must be of type string, null given, called in /code/vendor/symfony/turbo-sms-notifier/TurboSmsTransport.php on line 93 ``` Symfony use only one phone number for sent, as result we check only first `response_result`. Commits ------- 932dbe3 [Notifier][TurboSMS] Process partial accepted response from transport
2 parents 8773318 + 932dbe3 commit 28b1709

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

src/Symfony/Component/Notifier/Bridge/TurboSms/Tests/TurboSmsTransportTest.php

+37
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,43 @@ public function testSuccessfulSend()
9393
self::assertSame('f83f8868-5e46-c6cf-e4fb-615e5a293754', $sentMessage->getMessageId());
9494
}
9595

96+
public function testFailedSendWithPartialAccepted()
97+
{
98+
$response = $this->createMock(ResponseInterface::class);
99+
$response
100+
->expects(self::exactly(2))
101+
->method('getStatusCode')
102+
->willReturn(200)
103+
;
104+
$response
105+
->expects(self::once())
106+
->method('getContent')
107+
->willReturn(json_encode([
108+
'response_code' => 0,
109+
'response_status' => 'OK',
110+
'response_result' => [
111+
[
112+
'phone' => '380931234567',
113+
'response_code' => 406,
114+
'message_id' => null,
115+
'response_status' => 'NOT_ALLOWED_RECIPIENT_COUNTRY',
116+
],
117+
],
118+
]))
119+
;
120+
121+
$client = new MockHttpClient(static fn() => $response);
122+
123+
$message = new SmsMessage('380931234567', 'Test');
124+
125+
$transport = self::createTransport($client);
126+
127+
$this->expectException(TransportException::class);
128+
$this->expectExceptionMessage('Unable to send SMS with TurboSMS: Error code 406 with message "NOT_ALLOWED_RECIPIENT_COUNTRY".');
129+
130+
$transport->send($message);
131+
}
132+
96133
public function testFailedSend()
97134
{
98135
$response = $this->createMock(ResponseInterface::class);

src/Symfony/Component/Notifier/Bridge/TurboSms/TurboSmsTransport.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,14 @@ protected function doSend(MessageInterface $message): SentMessage
8989
if (200 === $response->getStatusCode()) {
9090
$success = $response->toArray(false);
9191

92+
if (null === $messageId = $success['response_result'][0]['message_id']) {
93+
$responseResult = $success['response_result'][0];
94+
95+
throw new TransportException(sprintf('Unable to send SMS with TurboSMS: Error code %d with message "%s".', (int) $responseResult['response_code'], $responseResult['response_status']), $response);
96+
}
97+
9298
$sentMessage = new SentMessage($message, (string) $this);
93-
$sentMessage->setMessageId($success['response_result'][0]['message_id']);
99+
$sentMessage->setMessageId($messageId);
94100

95101
return $sentMessage;
96102
}

0 commit comments

Comments
 (0)
0