/
githubmirror
/
framework
Обзор
Документация
Войти
/
githubmirror
/
framework
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
13.x
tests/Notifications/NotificationBroadcastChannelTest.php
161 строка
4 KB
Jason McCreary
[13.x] Mockery cleanup (#61117)
10 авг 2026, 20:23
Не верифицирован
10 авг 2026, 20:23
2ee40ee
Код
Авторство
О чём код?
<?php namespace Illuminate\Tests\Notifications; use Illuminate\Broadcasting\PrivateChannel; use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Notifications\Channels\BroadcastChannel; use Illuminate\Notifications\Events\BroadcastNotificationCreated; use Illuminate\Notifications\Messages\BroadcastMessage; use Illuminate\Notifications\Notification; use Mockery; use PHPUnit\Framework\TestCase; class NotificationBroadcastChannelTest extends TestCase { public function testDatabaseChannelCreatesDatabaseRecordWithProperData() { $notification = new NotificationBroadcastChannelTestNotification; $notification->id = 1; $notifiable = Mockery::mock(); $events = Mockery::mock(Dispatcher::class); $events->expects('dispatch')->with(Mockery::type(BroadcastNotificationCreated::class)); $channel = new BroadcastChannel($events); $channel->send($notifiable, $notification); } public function testNotificationIsBroadcastedOnCustomChannels() { $notification = new CustomChannelsTestNotification; $notification->id = 1; $notifiable = Mockery::mock(); $event = new BroadcastNotificationCreated( $notifiable, $notification, $notification->toArray($notifiable) ); $channels = $event->broadcastOn(); $this->assertEquals(new PrivateChannel('custom-channel'), $channels[0]); } public function testNotificationIsBroadcastedWithCustomEventName() { $notification = new CustomEventNameTestNotification; $notification->id = 1; $notifiable = Mockery::mock(); $event = new BroadcastNotificationCreated( $notifiable, $notification, $notification->toArray($notifiable) ); $eventName = $event->broadcastType(); $this->assertSame('custom.type', $eventName); } public function testNotificationIsBroadcastedWithCustomDataType() { $notification = new CustomEventNameTestNotification; $notification->id = 1; $notifiable = Mockery::mock(); $event = new BroadcastNotificationCreated( $notifiable, $notification, $notification->toArray($notifiable) ); $data = $event->broadcastWith(); $this->assertSame('custom.type', $data['type']); } public function testNotificationIsBroadcastedNow() { $notification = new TestNotificationBroadCastedNow; $notification->id = 1; $notifiable = Mockery::mock(); $events = Mockery::mock(Dispatcher::class); $events->expects('dispatch')->with(Mockery::on(function ($event) { return $event->connection === 'sync'; })); $channel = new BroadcastChannel($events); $channel->send($notifiable, $notification); } public function testNotificationIsBroadcastedWithCustomAdditionalPayload() { $notification = new CustomBroadcastWithTestNotification; $notification->id = 1; $notifiable = Mockery::mock(); $event = new BroadcastNotificationCreated( $notifiable, $notification, $notification->toArray($notifiable) ); $data = $event->broadcastWith(); $this->assertArrayHasKey('additional', $data); } } class NotificationBroadcastChannelTestNotification extends Notification { public function toArray($notifiable) { return ['invoice_id' => 1]; } } class CustomChannelsTestNotification extends Notification { public function toArray($notifiable) { return ['invoice_id' => 1]; } public function broadcastOn() { return [new PrivateChannel('custom-channel')]; } } class CustomEventNameTestNotification extends Notification { public function toArray($notifiable) { return ['invoice_id' => 1]; } public function broadcastType() { return 'custom.type'; } } class TestNotificationBroadCastedNow extends Notification { public function toArray($notifiable) { return ['invoice_id' => 1]; } public function toBroadcast() { return (new BroadcastMessage([]))->onConnection('sync'); } } class CustomBroadcastWithTestNotification extends Notification { public function toArray($notifiable) { return ['invoice_id' => 1]; } public function broadcastWith() { return ['id' => 1, 'type' => 'custom', 'additional' => 'custom']; } }