8000 [Notifier][TurboSMS] Process partial accepted response from transport · symfony/symfony@932dbe3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 932dbe3

Browse files
ZhukVnicolas-grekas
authored andcommitted
[Notifier][TurboSMS] Process partial accepted response from transport
1 parent f2e8474 commit 932dbe3

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