| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <?php
- namespace Illuminate\Tests\Notifications;
- use Illuminate\Notifications\Channels\DatabaseChannel;
- use Illuminate\Notifications\Messages\DatabaseMessage;
- use Illuminate\Notifications\Notification;
- use Mockery as m;
- use PHPUnit\Framework\TestCase;
- class NotificationDatabaseChannelTest extends TestCase
- {
- protected function tearDown(): void
- {
- m::close();
- }
- public function testDatabaseChannelCreatesDatabaseRecordWithProperData()
- {
- $notification = new NotificationDatabaseChannelTestNotification;
- $notification->id = 1;
- $notifiable = m::mock();
- $notifiable->shouldReceive('routeNotificationFor->create')->with([
- 'id' => 1,
- 'type' => get_class($notification),
- 'data' => ['invoice_id' => 1],
- 'read_at' => null,
- ]);
- $channel = new DatabaseChannel;
- $channel->send($notifiable, $notification);
- }
- public function testCorrectPayloadIsSentToDatabase()
- {
- $notification = new NotificationDatabaseChannelTestNotification;
- $notification->id = 1;
- $notifiable = m::mock();
- $notifiable->shouldReceive('routeNotificationFor->create')->with([
- 'id' => 1,
- 'type' => get_class($notification),
- 'data' => ['invoice_id' => 1],
- 'read_at' => null,
- 'something' => 'else',
- ]);
- $channel = new ExtendedDatabaseChannel;
- $channel->send($notifiable, $notification);
- }
- public function testCustomizeTypeIsSentToDatabase()
- {
- $notification = new NotificationDatabaseChannelCustomizeTypeTestNotification;
- $notification->id = 1;
- $notifiable = m::mock();
- $notifiable->shouldReceive('routeNotificationFor->create')->with([
- 'id' => 1,
- 'type' => 'MONTHLY',
- 'data' => ['invoice_id' => 1],
- 'read_at' => null,
- 'something' => 'else',
- ]);
- $channel = new ExtendedDatabaseChannel;
- $channel->send($notifiable, $notification);
- }
- }
- class NotificationDatabaseChannelTestNotification extends Notification
- {
- public function toDatabase($notifiable)
- {
- return new DatabaseMessage(['invoice_id' => 1]);
- }
- }
- class NotificationDatabaseChannelCustomizeTypeTestNotification extends Notification
- {
- public function toDatabase($notifiable)
- {
- return new DatabaseMessage(['invoice_id' => 1]);
- }
- public function databaseType()
- {
- return 'MONTHLY';
- }
- }
- class ExtendedDatabaseChannel extends DatabaseChannel
- {
- protected function buildPayload($notifiable, Notification $notification)
- {
- return array_merge(parent::buildPayload($notifiable, $notification), [
- 'something' => 'else',
- ]);
- }
- }
|