-
-
Notifications
You must be signed in to change notification settings - Fork 45
/
ClientTest.php
79 lines (72 loc) · 2.35 KB
/
ClientTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
/** @noinspection StaticClosureCanBeUsedInspection */
/** @noinspection PhpUnhandledExceptionInspection */
declare(strict_types=1);
/**
* Copyright (c) 2021-2024 guanguans<[email protected]>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*
* @see https://github.com/guanguans/notify
*/
namespace Guanguans\NotifyTests\Slack;
use Guanguans\Notify\Slack\Authenticator;
use Guanguans\Notify\Slack\Client;
use Guanguans\Notify\Slack\Messages\Message;
it('can send message', function (): void {
$authenticator = new Authenticator('https://hooks.slack.com/services/TPU9A98MT/B038KNUC0GY/6pKH3vfa3mjlUPcgLSjzR');
$client = new Client($authenticator);
$message = Message::make([
'channel' => '#general',
'attachments' => $attachment = [
'fallback' => 'This is fallback.',
'text' => 'This is text.',
'pretext' => 'This is pretext.',
'color' => '#36a64f',
'fields' => [
[
'title' => 'This is title.',
'value' => 'This is value.',
'short' => false,
],
],
],
'blocks' => [
$block = [
'type' => 'section',
'text' => [
'type' => 'mrkdwn',
'text' => 'This is text.',
],
],
],
'text' => 'This is text.',
'as_user' => true,
'icon_emoji' => ':ghost:',
'icon_url' => 'https://avatars.githubusercontent.com/u/22309277?v=4',
'link_names' => true,
'metadata' => [
'event_type' => 'task_created',
'event_payload' => [
'id' => '11223',
'title' => 'This is title.',
],
],
'mrkdwn' => true,
'parse' => 'full',
'reply_broadcast' => true,
// 'thread_ts' => '1621592155.003100',
'unfurl_links' => true,
'unfurl_media' => true,
'username' => 'This is username.',
])
->addAttachment($attachment)
->addBlock($block);
expect($client)
->mock([
response('ok'),
response('invalid_token', 403),
])
->assertCanSendMessage($message);
})->group(__DIR__, __FILE__);