8000 [Notifier] [Slack] Add SlackPlainTextInputBlock for Slack message by camilleislasse · Pull Request #60310 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Notifier] [Slack] Add SlackPlainTextInputBlock for Slack message #60310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: 7.4
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Add a testcase where this block is used in the transport
  • Loading branch information
camilleislasse committed May 2, 2025
commit 0af771d3d1b6be5c78d640d86b8335ac490ed934
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
namespace Symfony\Component\Notifier\Bridge\Slack\Tests;

use Symfony\Component\HttpClient\MockHttpClient;
use Symfony\Component\Notifier\Bridge\Slack\Block\SlackPlainTextInputBlock;
use Symfony\Component\Notifier\Bridge\Slack\Block\SlackSectionBlock;
use Symfony\Component\Notifier\Bridge\Slack\SlackOptions;
use Symfony\Component\Notifier\Bridge\Slack\SlackSentMessage;
use Symfony\Component\Notifier\Bridge\Slack\SlackTransport;
Expand Down Expand Up @@ -330,4 +332,44 @@ public function testUpdateMessage()

$this->assertSame('1503435956.000247', $sentMessage->getMessageId());
}

public function testSlackTransportSendsMessageWithInputBlock()
{
$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', 'channel' => 'C123456']));

$options = new SlackOptions();

$options->block((new SlackSectionBlock())->text($message));

$options->block((new SlackPlainTextInputBlock('Time spent', 'time_spent_input', 'Enter some text here')));

$expectedBody = json_encode([
'blocks' => $options->toArray()['blocks'],
'channel' => $channel,
'text' => $message,
]);

$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);

$sentMessage = $transport->send(new ChatMessage('testMessage', $options));

$this->assertSame('1503435956.000247', $sentMessage->getMessageId());
}
}
Loading
0