Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ protected function doSend(MessageInterface $message): SentMessage
}
$options['text'] = $message->getSubject();
$response = $this->client->request('POST', 'https://'.$this->getEndpoint().'/api/chat.postMessage', [
'json' => array_filter($options),
'json' => array_filter($options, function ($value): bool { return !\in_array($value, ['', [], null], true); }),
'auth_bearer' => $this->accessToken,
'headers' => [
'Content-Type' => 'application/json; charset=utf-8',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,56 @@ public function testSendWithNotification()
$this->assertSame('1503435956.000247', $sentMessage->getMessageId());
}

/**
* @testWith [true]
* [false]
*/
public function testSendWithBooleanOptionValue(bool $value)
{
$channel = 'testChannel';
$message = 'testMessage';

$response = $this->createMock(ResponseInterface::class);

$response->expects($this->exactly(2))
->method('getStatusCode')
->willReturn(200);

$response->expects($this->once())
->method('getContent')
->willReturn(json_encode(['ok' => true, 'ts' => '1503435956.000247']));

$options = new SlackOptions();
$options->asUser($value);
$options->linkNames($value);
$options->mrkdwn($value);
$options->unfurlLinks($value);
$options->unfurlMedia($value);
$notification = new Notification($message);
$chatMessage = ChatMessage::fromNotification($notification);
$chatMessage->options($options);

$expectedBody = json_encode([
'as_user' => $value,
'channel' => $channel,
'link_names' => $value,
'mrkdwn' => $value,
'text' => $message,
'unfurl_links' => $value,
'unfurl_media' => $value,
]);

$client = new MockHttpClient(function (string $method, string $url, array $options = []) use ($response, $expectedBody): ResponseInterface {
$this->assertJsonStringEqualsJsonString($expectedBody, $options['body']);

return $response;
});

$transport = self::createTransport($client, $channel);

$transport->send($chatMessage);
}

public function testSendWithInvalidOptions()
{
$this->expectException(LogicException::class);
Expand Down