Skip to content

Commit ee687df

Browse files
committed
bug #50893 [Notifier] Fix Esendex messages serialization (raphael-geffroy)
This PR was squashed before being merged into the 6.3 branch. Discussion ---------- [Notifier] Fix Esendex messages serialization | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #50892 | License | MIT It seems that the "messages" is missing a dimension since 6.3 and its serialized as an object instead of an array of objects. Commits ------- 3826587 [Notifier] Fix Esendex messages serialization
2 parents 3d5944f + 3826587 commit ee687df

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

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

Lines changed: 4 additions & 2 deletions
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

Lines changed: 34 additions & 0 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy