Skip to content

Commit 207e2f9

Browse files
leefantnicolas-grekas
authored andcommitted
Fix: Lack of recipient in case DSN does not have optional LIST_ID parameter.
According to https://developers.clicksend.com/docs/messaging/sms/other/send-sms#other/send-sms/t=request&path=messages/list_id we need to provide the "to" parameter or the "list_id" parameter. Also fixed forwarding FROM_EMAIL parameter to request.
1 parent 82a1563 commit 207e2f9

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

src/Symfony/Component/Notifier/Bridge/ClickSend/ClickSendTransport.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ protected function doSend(MessageInterface $message): SentMessage
7575
$options['from'] = $message->getFrom() ?: $this->from;
7676
$options['source'] ??= $this->source;
7777
$options['list_id'] ??= $this->listId;
78-
$options['from_email'] ?? $this->fromEmail;
78+
$options['from_email'] ??= $this->fromEmail;
7979

8080
if (isset($options['from']) && !preg_match('/^[a-zA-Z0-9\s]{3,11}$/', $options['from']) && !preg_match('/^\+[1-9]\d{1,14}$/', $options['from'])) {
8181
throw new InvalidArgumentException(sprintf('The "From" number "%s" is not a valid phone number, shortcode, or alphanumeric sender ID.', $options['from']));
8282
}
8383

84-
if ($options['list_id'] ?? false) {
84+
if (!$options['list_id']) {
8585
$options['to'] = $message->getPhone();
8686
}
8787

src/Symfony/Component/Notifier/Bridge/ClickSend/Tests/ClickSendTransportTest.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
final class ClickSendTransportTest extends TransportTestCase
2626
{
27-
public static function createTransport(?HttpClientInterface $client = null, string $from = 'test_from', string $source = 'test_source', int $listId = 99, string $fromEmail = 'foo@bar.com'): ClickSendTransport
27+
public static function createTransport(?HttpClientInterface $client = null, ?string $from = 'test_from', ?string $source = 'test_source', ?int $listId = 99, ?string $fromEmail = 'foo@bar.com'): ClickSendTransport
2828
{
2929
return new ClickSendTransport('test_username', 'test_key', $from, $source, $listId, $fromEmail, $client ?? new MockHttpClient());
3030
}
@@ -70,13 +70,40 @@ public function testNoInvalidArgumentExceptionIsThrownIfFromIsValid(string $from
7070
$body = json_decode($options['body'], true);
7171
self::assertIsArray($body);
7272
self::assertArrayHasKey('messages', $body);
73+
$message = reset($body['messages']);
74+
self::assertArrayHasKey('from_email', $message);
75+
self::assertArrayHasKey('list_id', $message);
76+
self::assertArrayNotHasKey('to', $message);
7377

7478
return $response;
7579
});
7680
$transport = $this->createTransport($client, $from);
7781
$transport->send($message);
7882
}
7983

84+
public function testNoInvalidArgumentExceptionIsThrownIfFromIsValidWithoutOptionalParameters()
85+
{
86+
$message = new SmsMessage('+33612345678', 'Hello!');
87+
$response = $this->createMock(ResponseInterface::class);
88+
$response->expects(self::exactly(2))->method('getStatusCode')->willReturn(200);
89+
$response->expects(self::once())->method('getContent')->willReturn('');
90+
$client = new MockHttpClient(function (string $method, string $url, array $options) use ($response): ResponseInterface {
91+
self::assertSame('POST', $method);
92+
self::assertSame('https://rest.clicksend.com/v3/sms/send', $url);
93+
94+
$body = json_decode($options['body'], true);
95+
self::assertIsArray($body);
96+
self::assertArrayHasKey('messages', $body);
97+
$message = reset($body['messages']);
98+
self::assertArrayNotHasKey('list_id', $message);
99+
self::assertArrayHasKey('to', $message);
100+
101+
return $response;
102+
});
103+
$transport = $this->createTransport($client, null, null, null, null);
104+
$transport->send($message);
105+
}
106+
80107
public static function toStringProvider(): iterable
81108
{
82109
yield ['clicksend://rest.clicksend.com?from=test_from&source=test_source&list_id=99&from_email=foo%40bar.com', self::createTransport()];

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