Skip to content

Navigation Menu

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 1e8310b

Browse filesBrowse files
committed
keep boolean options when their value is false
1 parent 48d093b commit 1e8310b
Copy full SHA for 1e8310b

File tree

2 files changed

+51
-1
lines changed
Filter options

2 files changed

+51
-1
lines changed

‎src/Symfony/Component/Notifier/Bridge/Slack/SlackTransport.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Notifier/Bridge/Slack/SlackTransport.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ protected function doSend(MessageInterface $message): SentMessage
8383
}
8484
$options['text'] = $message->getSubject();
8585
$response = $this->client->request('POST', 'https://'.$this->getEndpoint().'/api/chat.postMessage', [
86-
'json' => array_filter($options),
86+
'json' => array_filter($options, fn ($value) => !\in_array($value, ['', [], null], true)),
8787
'auth_bearer' => $this->accessToken,
8888
'headers' => [
8989
'Content-Type' => 'application/json; charset=utf-8',

‎src/Symfony/Component/Notifier/Bridge/Slack/Tests/SlackTransportTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Notifier/Bridge/Slack/Tests/SlackTransportTest.php
+50Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,56 @@ public function testSendWithNotification()
174174
$this->assertSame('1503435956.000247', $sentMessage->getMessageId());
175175
}
176176

177+
/**
178+
* @testWith [true]
179+
* [false]
180+
*/
181+
public function testSendWithBooleanOptionValue(bool $value)
182+
{
183+
$channel = 'testChannel';
184+
$message = 'testMessage';
185+
186+
$response = $this->createMock(ResponseInterface::class);
187+
188+
$response->expects($this->exactly(2))
189+
->method('getStatusCode')
190+
->willReturn(200);
191+
192+
$response->expects($this->once())
193+
->method('getContent')
194+
->willReturn(json_encode(['ok' => true, 'ts' => '1503435956.000247']));
195+
196+
$options = new SlackOptions();
197+
$options->asUser($value);
198+
$options->linkNames($value);
199+
$options->mrkdwn($value);
200+
$options->unfurlLinks($value);
201+
$options->unfurlMedia($value);
202+
$notification = new Notification($message);
203+
$chatMessage = ChatMessage::fromNotification($notification);
204+
$chatMessage->options($options);
205+
206+
$expectedBody = json_encode([
207+
'as_user' => $value,
208+
'channel' => $channel,
209+
'link_names' => $value,
210+
'mrkdwn' => $value,
211+
'text' => $message,
212+
'unfurl_links' => $value,
213+
'unfurl_media' => $value,
214+
]);
215+
216+
$client = new MockHttpClient(function (string $method, string $url, array $options = []) use ($response, $expectedBody): ResponseInterface {
217+
$this->assertJsonStringEqualsJsonString($expectedBody, $options['body']);
218+
219+
return $response;
220+
});
221+
222+
$transport = self::createTransport($client, $channel);
223+
224+
$transport->send($chatMessage);
225+
}
226+
177227
public function testSendWithInvalidOptions()
178228
{
179229
$this->expectException(LogicException::class);

0 commit comments

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