Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,43 @@ public function testSuccessfulSend()
self::assertSame('f83f8868-5e46-c6cf-e4fb-615e5a293754', $sentMessage->getMessageId());
}

public function testFailedSendWithPartialAccepted()
{
$response = $this->createMock(ResponseInterface::class);
$response
->expects(self::exactly(2))
->method('getStatusCode')
->willReturn(200)
;
$response
->expects(self::once())
->method('getContent')
->willReturn(json_encode([
'response_code' => 0,
'response_status' => 'OK',
'response_result' => [
[
'phone' => '380931234567',
'response_code' => 406,
'message_id' => null,
'response_status' => 'NOT_ALLOWED_RECIPIENT_COUNTRY',
],
],
]))
;

$client = new MockHttpClient(static fn() => $response);

$message = new SmsMessage('380931234567', 'Test');

$transport = self::createTransport($client);

$this->expectException(TransportException::class);
$this->expectExceptionMessage('Unable to send SMS with TurboSMS: Error code 406 with message "NOT_ALLOWED_RECIPIENT_COUNTRY".');

$transport->send($message);
}

public function testFailedSend()
{
$response = $this->createMock(ResponseInterface::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,14 @@ protected function doSend(MessageInterface $message): SentMessage
if (200 === $response->getStatusCode()) {
$success = $response->toArray(false);

if (null === $messageId = $success['response_result'][0]['message_id']) {
$responseResult = $success['response_result'][0];

throw new TransportException(sprintf('Unable to send SMS with TurboSMS: Error code %d with message "%s".', (int) $responseResult['response_code'], $responseResult['response_status']), $response);
}

$sentMessage = new SentMessage($message, (string) $this);
$sentMessage->setMessageId($success['response_result'][0]['message_id']);
$sentMessage->setMessageId($messageId);

return $sentMessage;
}
Expand Down