|
6 | 6 | use GuzzleHttp\Psr7\Response; |
7 | 7 | use Awssat\Notifications\Messages\DiscordMessage; |
8 | 8 | use GuzzleHttp\Client; |
9 | | -use Illuminate\Notifications\Messages\SlackMessage; |
10 | 9 | use Illuminate\Notifications\Notifiable; |
11 | 10 | use Illuminate\Notifications\Notification; |
12 | | -use Illuminate\Support\Carbon; |
13 | 11 | use Mockery as m; |
| 12 | +use PHPUnit\Framework\Attributes\DataProvider; |
14 | 13 | use PHPUnit\Framework\TestCase; |
15 | 14 |
|
16 | 15 | class NotificationDiscordChannelTest extends TestCase |
@@ -39,66 +38,23 @@ protected function tearDown(): void |
39 | 38 | m::close(); |
40 | 39 | } |
41 | 40 |
|
42 | | - /** |
43 | | - * @dataProvider payloadDataProvider |
44 | | - * @param \Illuminate\Notifications\Notification $notification |
45 | | - * @param array $payload |
46 | | - */ |
| 41 | + #[DataProvider('payloadDataProvider')] |
47 | 42 | public function testCorrectPayloadIsSentToDiscord(Notification $notification, string $url, array $payload) |
48 | 43 | { |
49 | 44 | $this->guzzleHttp->shouldReceive('post')->andReturnUsing(function ($argUrl, $argPayload) use ($payload, $url) { |
50 | 45 | $this->assertEquals($argUrl, $url); |
51 | 46 | $this->assertEquals($argPayload, $payload); |
52 | | - |
| 47 | + |
53 | 48 | return new Response(); |
54 | 49 | }); |
55 | 50 |
|
56 | 51 | $this->discordChannel->send(new NotificationDiscordChannelTestNotifiable, $notification); |
57 | 52 | } |
58 | 53 |
|
59 | | - public static function payloadDataProvider() |
| 54 | + public static function payloadDataProvider() |
60 | 55 | { |
61 | 56 | return [ |
62 | 57 | 'payloadWithDiscord' => self::getPayloadWithDiscord(), |
63 | | - 'payloadWithSlackMessage' => self::getPayloadWithSlackMessage(), |
64 | | - ]; |
65 | | - } |
66 | | - |
67 | | - private static function getPayloadWithSlackMessage() |
68 | | - { |
69 | | - return [ |
70 | | - new NotificationDiscordChannelTestNotificationWithSlack, |
71 | | - 'url/slack', |
72 | | - [ |
73 | | - 'json' => [ |
74 | | - 'username' => 'Ghostbot', |
75 | | - 'icon_emoji' => ':ghost:', |
76 | | - 'channel' => '#ghost-talk', |
77 | | - 'text' => 'Content', |
78 | | - 'attachments' => [ |
79 | | - [ |
80 | | - 'title' => 'Laravel', |
81 | | - 'title_link' => 'https://laravel.com', |
82 | | - 'text' => 'Attachment Content', |
83 | | - 'fallback' => 'Attachment Fallback', |
84 | | - 'fields' => [ |
85 | | - [ |
86 | | - 'title' => 'Project', |
87 | | - 'value' => 'Laravel', |
88 | | - 'short' => true, |
89 | | - ], |
90 | | - ], |
91 | | - 'mrkdwn_in' => ['text'], |
92 | | - 'footer' => 'Laravel', |
93 | | - 'footer_icon' => 'https://laravel.com/fake.png', |
94 | | - 'author_name' => 'Author', |
95 | | - 'author_link' => 'https://laravel.com/fake_author', |
96 | | - 'author_icon' => 'https://laravel.com/fake_author.png', |
97 | | - 'ts' => 1234567890, |
98 | | - ], |
99 | | - ], |
100 | | - ], |
101 | | - ], |
102 | 58 | ]; |
103 | 59 | } |
104 | 60 |
|
@@ -148,32 +104,6 @@ public function routeNotificationForDiscord() |
148 | 104 | } |
149 | 105 | } |
150 | 106 |
|
151 | | -class NotificationDiscordChannelTestNotificationWithSlack extends Notification |
152 | | -{ |
153 | | - public function toDiscord($notifiable) |
154 | | - { |
155 | | - return (new SlackMessage) |
156 | | - ->from('Ghostbot', ':ghost:') |
157 | | - ->to('#ghost-talk') |
158 | | - ->content('Content') |
159 | | - ->attachment(function ($attachment) { |
160 | | - $timestamp = m::mock(Carbon::class); |
161 | | - $timestamp->shouldReceive('getTimestamp')->andReturn(1234567890); |
162 | | - $attachment->title('Laravel', 'https://laravel.com') |
163 | | - ->content('Attachment Content') |
164 | | - ->fallback('Attachment Fallback') |
165 | | - ->fields([ |
166 | | - 'Project' => 'Laravel', |
167 | | - ]) |
168 | | - ->footer('Laravel') |
169 | | - ->footerIcon('https://laravel.com/fake.png') |
170 | | - ->markdown(['text']) |
171 | | - ->author('Author', 'https://laravel.com/fake_author', 'https://laravel.com/fake_author.png') |
172 | | - ->timestamp($timestamp); |
173 | | - }); |
174 | | - } |
175 | | -} |
176 | | - |
177 | 107 | class NotificationDiscordChannelTestNotificationWithDiscordMessage extends Notification |
178 | 108 | { |
179 | 109 | public function toDiscord($notifiable) |
|
0 commit comments