Skip to content

Commit d9b30a7

Browse files
committed
keep boolean options when their value is false
1 parent 48d093b commit d9b30a7

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

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

Lines 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

Lines 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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy