|
24 | 24 |
|
25 | 25 | final class ClickSendTransportTest extends TransportTestCase
|
26 | 26 | {
|
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 |
28 | 28 | {
|
29 | 29 | return new ClickSendTransport('test_username', 'test_key', $from, $source, $listId, $fromEmail, $client ?? new MockHttpClient());
|
30 | 30 | }
|
@@ -70,13 +70,40 @@ public function testNoInvalidArgumentExceptionIsThrownIfFromIsValid(string $from
|
70 | 70 | $body = json_decode($options['body'], true);
|
71 | 71 | self::assertIsArray($body);
|
72 | 72 | 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); |
73 | 77 |
|
74 | 78 | return $response;
|
75 | 79 | });
|
76 | 80 | $transport = $this->createTransport($client, $from);
|
77 | 81 | $transport->send($message);
|
78 | 82 | }
|
79 | 83 |
|
| 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 | + |
80 | 107 | public static function toStringProvider(): iterable
|
81 | 108 | {
|
82 | 109 | yield ['clicksend://rest.clicksend.com?from=test_from&source=test_source&list_id=99&from_email=foo%40bar.com', self::createTransport()];
|
|
0 commit comments