10000 Correct process partial accepted response from TurboSMS transport · symfony/symfony@8d4cdd4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8d4cdd4

Browse files
committed
Correct process partial accepted response from TurboSMS transport
1 parent f2e8474 commit 8d4cdd4

File tree

2 files changed

+52
-7
lines changed

2 files changed

+52
-7
lines changed

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

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public static function unsupportedMessagesProvider(): iterable
4646
yield [new DummyMessage()];
4747
}
4848

49-
public function testSuccessfulSend()
49+
public function testSuccessfulSend(): void
5050
{
5151
$response = $this->createMock(ResponseInterface::class);
5252
$response
@@ -93,7 +93,44 @@ public function testSuccessfulSend()
9393
self::assertSame('f83f8868-5e46-c6cf-e4fb-615e5a293754', $sentMessage->getMessageId());
9494
}
9595

96-
public function testFailedSend()
96+
public function testFailedSendWithPartialAccepted(): void
97+
{
98+
8000 $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+
133+
public function testFailedSend(): void
97134
{
98135
$response = $this->createMock(ResponseInterface::class);
99136
$response
@@ -123,7 +160,7 @@ public function testFailedSend()
123160
$transport->send($message);
124161
}
125162

126-
public function testInvalidFrom()
163+
public function testInvalidFrom(): void
127164
{
128165
$this->expectException(LengthException::class);
129166
$this->expectExceptionMessage('The sender length of a TurboSMS message must not exceed 20 characters.');
@@ -134,7 +171,7 @@ public function testInvalidFrom()
134171
$transport->send($message);
135172
}
136173

137-
public function testInvalidSubjectWithLatinSymbols()
174+
public function testInvalidSubjectWithLatinSymbols(): void
138175
{
139176
$message = new SmsMessage('380931234567', str_repeat('z', 1522));
140177
$transport = new TurboSmsTransport('authToken', 'sender', $this->createMock(HttpClientInterface::class));
@@ -145,7 +182,7 @@ public function testInvalidSubjectWithLatinSymbols()
145182
$transport->send($message);
146183
}
147184

148-
public function testInvalidSubjectWithCyrillicSymbols()
185+
public function testInvalidSubjectWithCyrillicSymbols(): void
149186
{
150187
$message = new SmsMessage('380931234567', str_repeat('z', 661).'Й');
151188
$transport = new TurboSmsTransport('authToken', 'sender', $this->createMock(HttpClientInterface::class));
@@ -156,7 +193,7 @@ public function testInvalidSubjectWithCyrillicSymbols()
156193
$transport->send($message);
157194
}
158195

159-
public function testSmsMessageWithInvalidFrom()
196+
public function testSmsMessageWithInvalidFrom(): void
160197
{
161198
$transport = $this->createTransport();
162199

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

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

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

95103
return $sentMessage;
96104
}

0 commit comments

Comments
 (0)
0