| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- <?php
- namespace Illuminate\Tests\Notifications;
- use Illuminate\Contracts\Database\ModelIdentifier;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Notifications\AnonymousNotifiable;
- use Illuminate\Notifications\ChannelManager;
- use Illuminate\Notifications\Notifiable;
- use Illuminate\Notifications\SendQueuedNotifications;
- use Illuminate\Support\Collection;
- use Mockery as m;
- use PHPUnit\Framework\TestCase;
- class NotificationSendQueuedNotificationTest extends TestCase
- {
- protected function tearDown(): void
- {
- m::close();
- }
- public function testNotificationsCanBeSent()
- {
- $job = new SendQueuedNotifications('notifiables', 'notification');
- $manager = m::mock(ChannelManager::class);
- $manager->shouldReceive('sendNow')->once()->withArgs(function ($notifiables, $notification, $channels) {
- return $notifiables instanceof Collection && $notifiables->toArray() === ['notifiables']
- && $notification === 'notification'
- && $channels === null;
- });
- $job->handle($manager);
- }
- public function testSerializationOfNotifiableModel()
- {
- $identifier = new ModelIdentifier(NotifiableUser::class, [null], [], null);
- $serializedIdentifier = serialize($identifier);
- $job = new SendQueuedNotifications(new NotifiableUser, 'notification');
- $serialized = serialize($job);
- $this->assertStringContainsString($serializedIdentifier, $serialized);
- }
- public function testSerializationOfNormalNotifiable()
- {
- $notifiable = new AnonymousNotifiable;
- $serializedNotifiable = serialize($notifiable);
- $job = new SendQueuedNotifications($notifiable, 'notification');
- $serialized = serialize($job);
- $this->assertStringContainsString($serializedNotifiable, $serialized);
- }
- }
- class NotifiableUser extends Model
- {
- use Notifiable;
- public $table = 'users';
- public $timestamps = false;
- }
|