Skip to content

Commit 1249eea

Browse files
authored
Merge pull request #14 from awssat/copilot/merge-laravel-13-compatibility
Add Laravel 13 CI coverage and support new Slack message class in Discord channel
2 parents 6c817a2 + e1fbe65 commit 1249eea

4 files changed

Lines changed: 18 additions & 82 deletions

File tree

.github/workflows/tests.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,16 @@ jobs:
1212
fail-fast: true
1313
matrix:
1414
php: [8.1, 8.2, 8.3]
15-
laravel: ['10.*', '11.*', '12.*']
15+
laravel: ['10.*', '11.*', '12.*', '13.*']
1616
exclude:
1717
- laravel: 11.*
1818
php: 8.1
1919
- laravel: 12.*
2020
php: 8.1
21+
- laravel: 13.*
22+
php: 8.1
23+
- laravel: 13.*
24+
php: 8.2
2125

2226
name: P${{ matrix.php }} - L${{ matrix.laravel }}
2327

composer.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
}
1515
],
1616
"require": {
17-
"php": "^7.1.3|^8.0",
18-
"guzzlehttp/guzzle": "^6.0|^7.0",
19-
"illuminate/notifications": "~5.8.0|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0",
20-
"laravel/slack-notification-channel": "^2.0|^3.2"
17+
"php": "^8.1",
18+
"guzzlehttp/guzzle": "^7.0",
19+
"illuminate/notifications": "^10.0|^11.0|^12.0|^13.0",
20+
"laravel/slack-notification-channel": "^3.2"
2121
},
2222
"require-dev": {
23-
"mockery/mockery": "^1.4 || ^1.6",
24-
"phpunit/phpunit": "^7.0|^8.0|^9.0|^10.1"
23+
"mockery/mockery": "^1.6",
24+
"phpunit/phpunit": "^10.1|^11.0|^12.0"
2525
},
2626
"autoload": {
2727
"psr-4": {

src/Channels/DiscordWebhookChannel.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
use Awssat\Notifications\Messages\DiscordEmbedField;
77
use Awssat\Notifications\Messages\DiscordMessage;
88
use GuzzleHttp\Client as HttpClient;
9+
use Illuminate\Notifications\Channels\SlackWebhookChannel;
910
use Illuminate\Notifications\Messages\SlackMessage;
11+
use Illuminate\Notifications\Slack\SlackMessage as LaravelSlackMessage;
1012
use Illuminate\Notifications\Notification;
1113

1214
class DiscordWebhookChannel
@@ -45,7 +47,7 @@ public function send($notifiable, Notification $notification)
4547

4648
$message = $notification->toDiscord($notifiable);
4749

48-
if($message instanceof SlackMessage) {
50+
if ($message instanceof SlackMessage || $message instanceof LaravelSlackMessage) {
4951
$slackWebhook = new SlackWebhookChannel($this->http);
5052
return $this->http->post($url . '/slack', $slackWebhook->buildJsonPayload($message));
5153
}

tests/NotificationDiscordChannelTest.php

Lines changed: 4 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66
use GuzzleHttp\Psr7\Response;
77
use Awssat\Notifications\Messages\DiscordMessage;
88
use GuzzleHttp\Client;
9-
use Illuminate\Notifications\Messages\SlackMessage;
109
use Illuminate\Notifications\Notifiable;
1110
use Illuminate\Notifications\Notification;
12-
use Illuminate\Support\Carbon;
1311
use Mockery as m;
12+
use PHPUnit\Framework\Attributes\DataProvider;
1413
use PHPUnit\Framework\TestCase;
1514

1615
class NotificationDiscordChannelTest extends TestCase
@@ -39,66 +38,23 @@ protected function tearDown(): void
3938
m::close();
4039
}
4140

42-
/**
43-
* @dataProvider payloadDataProvider
44-
* @param \Illuminate\Notifications\Notification $notification
45-
* @param array $payload
46-
*/
41+
#[DataProvider('payloadDataProvider')]
4742
public function testCorrectPayloadIsSentToDiscord(Notification $notification, string $url, array $payload)
4843
{
4944
$this->guzzleHttp->shouldReceive('post')->andReturnUsing(function ($argUrl, $argPayload) use ($payload, $url) {
5045
$this->assertEquals($argUrl, $url);
5146
$this->assertEquals($argPayload, $payload);
52-
47+
5348
return new Response();
5449
});
5550

5651
$this->discordChannel->send(new NotificationDiscordChannelTestNotifiable, $notification);
5752
}
5853

59-
public static function payloadDataProvider()
54+
public static function payloadDataProvider()
6055
{
6156
return [
6257
'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-
],
10258
];
10359
}
10460

@@ -148,32 +104,6 @@ public function routeNotificationForDiscord()
148104
}
149105
}
150106

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-
177107
class NotificationDiscordChannelTestNotificationWithDiscordMessage extends Notification
178108
{
179109
public function toDiscord($notifiable)

0 commit comments

Comments
 (0)