|
12 | 12 | namespace Symfony\Component\Notifier\Bridge\Smsmode\Tests;
|
13 | 13 |
|
14 | 14 | use Symfony\Component\HttpClient\MockHttpClient;
|
| 15 | +use Symfony\Component\HttpFoundation\Response; |
15 | 16 | use Symfony\Component\Notifier\Bridge\Smsmode\SmsmodeOptions;
|
16 | 17 | use Symfony\Component\Notifier\Bridge\Smsmode\SmsmodeTransport;
|
17 | 18 | use Symfony\Component\Notifier\Exception\InvalidArgumentException;
|
18 | 19 | use Symfony\Component\Notifier\Message\ChatMessage;
|
19 |
| -use Symfony\Component\Notifier\Message\MessageInterface; |
20 | 20 | use Symfony\Component\Notifier\Message\SmsMessage;
|
21 | 21 | use Symfony\Component\Notifier\Test\TransportTestCase;
|
22 | 22 | use Symfony\Component\Notifier\Tests\Transport\DummyMessage;
|
|
25 | 25 |
|
26 | 26 | final class SmsmodeTransportTest extends TransportTestCase
|
27 | 27 | {
|
| 28 | + private const DEFAULT_URL = "https://rest.smsmode.com/sms/v1/messages"; |
| 29 | + |
28 | 30 | public static function createTransport(HttpClientInterface $client = null, string $from = 'test_from'): SmsmodeTransport
|
29 | 31 | {
|
30 | 32 | return new SmsmodeTransport('test_api_key', $from, $client ?? new MockHttpClient());
|
@@ -81,6 +83,44 @@ public function testNoInvalidArgumentExceptionIsThrownIfFromIsValid(string $from
|
81 | 83 | self::assertSame('foo', $sentMessage->getMessageId());
|
82 | 84 | }
|
83 | 85 |
|
| 86 | + public function testIfMandatoryHttpClientRequestHeaderContentTypeIsMissing() |
| 87 | + { |
| 88 | + $response = $this->createMock(ResponseInterface::class); |
| 89 | + $response->expects(self::exactly(2))->method('getStatusCode')->willReturn(Response::HTTP_UNSUPPORTED_MEDIA_TYPE); |
| 90 | + |
| 91 | + $options = [ |
| 92 | + 'headers' => [ |
| 93 | + 'X-Api-Key' => 'test_api_key', |
| 94 | + 'Accept' => 'application/json', |
| 95 | + ], |
| 96 | + ]; |
| 97 | + |
| 98 | + $client = new MockHttpClient($response); |
| 99 | + |
| 100 | + $response = $client->request('POST', self::DEFAULT_URL, $options); |
| 101 | + |
| 102 | + self::assertEquals(Response::HTTP_UNSUPPORTED_MEDIA_TYPE, $response->getStatusCode()); |
| 103 | + } |
| 104 | + |
| 105 | + public function testIfMandatoryHttpClientRequestHeaderAcceptIsMissing() |
| 106 | + { |
| 107 | + $response = $this->createMock(ResponseInterface::class); |
| 108 | + $response->expects(self::exactly(2))->method('getStatusCode')->willReturn(Response::HTTP_NOT_ACCEPTABLE); |
| 109 | + |
| 110 | + $options = [ |
| 111 | + 'headers' => [ |
| 112 | + 'X-Api-Key' => 'test_api_key', |
| 113 | + 'Content-type' => 'application/json', |
| 114 | + ], |
| 115 | + ]; |
| 116 | + |
| 117 | + $client = new MockHttpClient($response); |
| 118 | + |
| 119 | + $response = $client->request('POST', self::DEFAULT_URL, $options); |
| 120 | + |
| 121 | + self::assertEquals(Response::HTTP_NOT_ACCEPTABLE, $response->getStatusCode()); |
| 122 | + } |
| 123 | + |
84 | 124 | public static function toStringProvider(): iterable
|
85 | 125 | {
|
86 | 126 | yield ['smsmode://rest.smsmode.com?from=test_from', self::createTransport()];
|
|
0 commit comments