Skip to content

Commit 3826587

Browse files
raphael-geffroyfabpot
authored andcommitted
[Notifier] Fix Esendex messages serialization
1 parent f06bd17 commit 3826587

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

src/Symfony/Component/Notifier/Bridge/Esendex/EsendexTransport.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,10 @@ protected function doSend(MessageInterface $message): SentMessage
6060
$options = $message->getOptions()?->toArray() ?? [];
6161
$options['from'] = $message->getFrom() ?: $this->from;
6262
$options['messages'] = [
63-
'to' => $message->getPhone(),
64-
'body' => $message->getSubject(),
63+
[
64+
'to' => $message->getPhone(),
65+
'body' => $message->getSubject(),
66+
],
6567
];
6668
$options['accountreference'] ??= $this->accountReference;
6769

src/Symfony/Component/Notifier/Bridge/Esendex/Tests/EsendexTransportTest.php

+34
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,38 @@ public function testSendWithSuccessfulResponseDispatchesMessageEvent()
102102

103103
$this->assertSame($messageId, $sentMessage->getMessageId());
104104
}
105+
106+
public function testSentMessageContainsAnArrayOfMessages()
107+
{
108+
$messageId = bin2hex(random_bytes(7));
109+
$response = $this->createMock(ResponseInterface::class);
110+
$response->expects($this->exactly(2))
111+
->method('getStatusCode')
112+
->willReturn(200);
113+
$response->expects($this->once())
114+
->method('getContent')
115+
->willReturn(json_encode(['batch' => ['messageheaders' => [['id' => $messageId]]]]));
116+
117+
$requestOptions = [];
118+
$client = new MockHttpClient(static function ($method, $url, $options) use (&$requestOptions, $response): ResponseInterface {
119+
$requestOptions = $options;
120+
121+
return $response;
122+
});
123+
124+
$transport = self::createTransport($client);
125+
126+
$transport->send(new SmsMessage('phone', 'testMessage'));
127+
128+
$body = json_decode($requestOptions['body'] ?? '');
129+
130+
$messages = $body->messages;
131+
$this->assertIsArray($messages);
132+
$this->assertCount(1, $messages);
133+
134+
$message = $messages[array_key_first($messages)];
135+
$this->assertIsObject($message);
136+
$this->assertTrue(property_exists($message, 'to'));
137+
$this->assertTrue(property_exists($message, 'body'));
138+
}
105139
}

0 commit comments

Comments
 (0)