Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a99b697

Browse filesBrowse files
bug #51629 [Notifier] Fix Smsmode HttpClient mandatory headers (inwebo)
This PR was squashed before being merged into the 6.3 branch. Discussion ---------- [Notifier] Fix Smsmode HttpClient mandatory headers | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | no | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> As mentioned in the documentation https://dev.smsmode.com/sms/v1/home in section Content-Type & URL Encoding. HTTP request and response bodies are JSON objects, which is why Accept and Content-Type headers are mandatory and are implicitly added when the request is executed with the TEST button. If the Accept header is missing, a Not Acceptable (406) HTTP status code is returned. (Accept: application/json) The Content-Type header is only needed with POST and PATCH methods. If it is missing, an Unsupported Media Type (415) Commits ------- a3dd8dc [Notifier] Fix Smsmode HttpClient mandatory headers
2 parents 4ba165a + a3dd8dc commit a99b697
Copy full SHA for a99b697

File tree

Expand file treeCollapse file tree

2 files changed

+25
-2
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+25
-2
lines changed

‎src/Symfony/Component/Notifier/Bridge/Smsmode/SmsmodeTransport.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Notifier/Bridge/Smsmode/SmsmodeTransport.php
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ protected function doSend(MessageInterface $message): SentMessage
6969
}
7070

7171
$response = $this->client->request('POST', $endpoint, [
72-
'headers' => ['X-Api-Key' => $this->apiKey],
72+
'headers' => [
73+
'X-Api-Key' => $this->apiKey,
74+
'Accept' => 'application/json',
75+
],
7376
'json' => array_filter($options),
7477
]);
7578

‎src/Symfony/Component/Notifier/Bridge/Smsmode/Tests/SmsmodeTransportTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Notifier/Bridge/Smsmode/Tests/SmsmodeTransportTest.php
+21-1Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use Symfony\Component\Notifier\Bridge\Smsmode\SmsmodeTransport;
1717
use Symfony\Component\Notifier\Exception\InvalidArgumentException;
1818
use Symfony\Component\Notifier\Message\ChatMessage;
19-
use Symfony\Component\Notifier\Message\MessageInterface;
2019
use Symfony\Component\Notifier\Message\SmsMessage;
2120
use Symfony\Component\Notifier\Test\TransportTestCase;
2221
use Symfony\Component\Notifier\Tests\Transport\DummyMessage;
@@ -81,6 +80,27 @@ public function testNoInvalidArgumentExceptionIsThrownIfFromIsValid(string $from
8180
self::assertSame('foo', $sentMessage->getMessageId());
8281
}
8382

83+
public function testHttpClientHasMandatoryHeaderAccept()
84+
{
85+
$message = new SmsMessage('+33612345678', 'Hello!');
86+
87+
$response = $this->createMock(ResponseInterface::class);
88+
$response->expects(self::exactly(2))->method('getStatusCode')->willReturn(201);
89+
$response->expects(self::once())->method('getContent')->willReturn(json_encode(['messageId' => 'foo']));
90+
91+
$transport = $this->createTransport(new MockHttpClient(function (string $method, string $url, array $options) use ($response): ResponseInterface {
92+
$this->assertSame('POST', $method);
93+
$this->assertSame('https://rest.smsmode.com/sms/v1/messages', $url);
94+
$this->assertSame('Accept: application/json', $options['normalized_headers']['accept'][0]);
95+
96+
return $response;
97+
}), 'foo');
98+
99+
$result = $transport->send($message);
100+
101+
$this->assertSame('foo', $result->getMessageId());
102+
}
103+
84104
public static function toStringProvider(): iterable
85105
{
86106
yield ['smsmode://rest.smsmode.com?from=test_from', self::createTransport()];

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.