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 @@ -75,13 +75,13 @@ protected function doSend(MessageInterface $message): SentMessage
$options['from'] = $message->getFrom() ?: $this->from;
$options['source'] ??= $this->source;
$options['list_id'] ??= $this->listId;
$options['from_email'] ?? $this->fromEmail;
$options['from_email'] ??= $this->fromEmail;

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

final class ClickSendTransportTest extends TransportTestCase
{
public static function createTransport(?HttpClientInterface $client = null, string $from = 'test_from', string $source = 'test_source', int $listId = 99, string $fromEmail = 'foo@bar.com'): ClickSendTransport
public static function createTransport(?HttpClientInterface $client = null, ?string $from = 'test_from', ?string $source = 'test_source', ?int $listId = 99, ?string $fromEmail = 'foo@bar.com'): ClickSendTransport
{
return new ClickSendTransport('test_username', 'test_key', $from, $source, $listId, $fromEmail, $client ?? new MockHttpClient());
}
Expand Down Expand Up @@ -70,13 +70,40 @@ public function testNoInvalidArgumentExceptionIsThrownIfFromIsValid(string $from
$body = json_decode($options['body'], true);
self::assertIsArray($body);
self::assertArrayHasKey('messages', $body);
$message = reset($body['messages']);
self::assertArrayHasKey('from_email', $message);
self::assertArrayHasKey('list_id', $message);
self::assertArrayNotHasKey('to', $message);

return $response;
});
$transport = $this->createTransport($client, $from);
$transport->send($message);
}

public function testNoInvalidArgumentExceptionIsThrownIfFromIsValidWithoutOptionalParameters()
{
$message = new SmsMessage('+33612345678', 'Hello!');
$response = $this->createMock(ResponseInterface::class);
$response->expects(self::exactly(2))->method('getStatusCode')->willReturn(200);
$response->expects(self::once())->method('getContent')->willReturn('');
$client = new MockHttpClient(function (string $method, string $url, array $options) use ($response): ResponseInterface {
self::assertSame('POST', $method);
self::assertSame('https://rest.clicksend.com/v3/sms/send', $url);

$body = json_decode($options['body'], true);
self::assertIsArray($body);
self::assertArrayHasKey('messages', $body);
$message = reset($body['messages']);
self::assertArrayNotHasKey('list_id', $message);
self::assertArrayHasKey('to', $message);

return $response;
});
$transport = $this->createTransport($client, null, null, null, null);
$transport->send($message);
}

public static function toStringProvider(): iterable
{
yield ['clicksend://rest.clicksend.com?from=test_from&source=test_source&list_id=99&from_email=foo%40bar.com', self::createTransport()];
Expand Down
Loading