Skip to content

Commit 19e1542

Browse files
authored
Merge pull request #1 from descom-es/notification
Notifications queue custom
2 parents c996bca + d4c4686 commit 19e1542

File tree

5 files changed

+90
-1
lines changed

5 files changed

+90
-1
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace DescomMarket\Common\Notifications;
4+
5+
use Illuminate\Bus\Queueable;
6+
use Illuminate\Contracts\Queue\ShouldQueue;
7+
use Illuminate\Notifications\Notification;
8+
9+
abstract class NotificationDescomMarket extends Notification implements ShouldQueue
10+
{
11+
use Queueable;
12+
13+
public function __construct()
14+
{
15+
$this->onConnection(config('dm360.notifications.queue.connection', 'sync'));
16+
17+
$this->onQueue(config('dm360.notifications.queue.name'));
18+
}
19+
}

src/Notifications/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Notifications
2+
3+
## NotificationDescomMarket
4+
5+
NotificationDescomMarket you can extend to create your own queue notification.
6+
7+
You need define this config in `dm360.php` file;
8+
9+
```php
10+
'notification' => [
11+
'queue' => [
12+
'connection' => 'database',
13+
'name' => 'default',
14+
],
15+
],
16+
```
17+
18+
Then you need extends `NotificationDescomMarket` for your notifications
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace DescomMarket\Common\Tests\Feature\Notifications;
4+
5+
use DescomMarket\Common\Notifiables\AdminNotifiable;
6+
use DescomMarket\Common\Tests\Stubs\TestNotification;
7+
use DescomMarket\Common\Tests\TestCase;
8+
use Illuminate\Support\Facades\Notification;
9+
10+
class NotificationDescomMarketTest extends TestCase
11+
{
12+
public function testSendReportNotification()
13+
{
14+
Notification::fake();
15+
16+
AdminNotifiable::configEmails(['sample@example.com']);
17+
18+
(new AdminNotifiable())->notify(new TestNotification('message'));
19+
20+
Notification::assertSentTo(
21+
(new AdminNotifiable()),
22+
TestNotification::class
23+
);
24+
}
25+
}

tests/Feature/Notifications/ReportNotificationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace DescomMarket\Common\Tests\Feature;
3+
namespace DescomMarket\Common\Tests\Feature\Notifications;
44

55
use DescomMarket\Common\Notifiables\AdminNotifiable;
66
use DescomMarket\Common\Notifications\Admin\ReportNotification;

tests/Stubs/TestNotification.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace DescomMarket\Common\Tests\Stubs;
4+
5+
use DescomMarket\Common\Notifications\NotificationDescomMarket;
6+
use Illuminate\Notifications\Messages\MailMessage;
7+
8+
class TestNotification extends NotificationDescomMarket
9+
{
10+
public function __construct(public readonly string $message)
11+
{
12+
}
13+
14+
public function via($notifiable): array
15+
{
16+
return ['mail'];
17+
}
18+
19+
public function toMail($notifiable): MailMessage
20+
{
21+
return (new MailMessage())
22+
->subject('Test Notification')
23+
->line($this->message);
24+
}
25+
26+
27+
}

0 commit comments

Comments
 (0)