/
githubmirror
/
framework
Обзор
Документация
Войти
/
githubmirror
/
framework
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
13.x
tests/Integration/Notifications/SendingNotificationsViaAnonymousNotifiableTest.php
90 строк
3 KB
Mior Muhammad Zaki
[10.x] Test Improvements for Mail & Notifications tests (#50690)
21 мар 2024, 11:44
Не верифицирован
21 мар 2024, 11:44
3d3063c
Код
Авторство
О чём код?
<?php namespace Illuminate\Tests\Integration\Notifications; use Illuminate\Notifications\AnonymousNotifiable; use Illuminate\Notifications\Notification; use Illuminate\Support\Facades\Notification as NotificationFacade; use Illuminate\Support\Testing\Fakes\NotificationFake; use Orchestra\Testbench\TestCase; class SendingNotificationsViaAnonymousNotifiableTest extends TestCase { public function testMailIsSent() { $notifiable = (new AnonymousNotifiable) ->route('testchannel', 'enzo') ->route('anothertestchannel', 'enzo@deepblue.com'); NotificationFacade::send( $notifiable, new TestMailNotificationForAnonymousNotifiable ); $this->assertEquals([ 'enzo', 'enzo@deepblue.com', ], $_SERVER['__notifiable.route']); } public function testAnonymousNotifiableWithMultipleRoutes() { $_SERVER['__notifiable.route'] = []; NotificationFacade::routes([ 'testchannel' => 'enzo', 'anothertestchannel' => 'enzo@deepblue.com', ])->notify(new TestMailNotificationForAnonymousNotifiable()); $this->assertEquals([ 'enzo', 'enzo@deepblue.com', ], $_SERVER['__notifiable.route']); } public function testFaking() { $fake = NotificationFacade::fake(); $this->assertInstanceOf(NotificationFake::class, $fake); $notifiable = (new AnonymousNotifiable) ->route('testchannel', 'enzo') ->route('anothertestchannel', 'enzo@deepblue.com'); NotificationFacade::locale('it')->send( $notifiable, new TestMailNotificationForAnonymousNotifiable ); NotificationFacade::assertSentTo(new AnonymousNotifiable, TestMailNotificationForAnonymousNotifiable::class, function ($notification, $channels, $notifiable, $locale) { return $notifiable->routes['testchannel'] === 'enzo' && $notifiable->routes['anothertestchannel'] === 'enzo@deepblue.com' && $locale === 'it'; } ); } } class TestMailNotificationForAnonymousNotifiable extends Notification { public function via($notifiable) { return [TestCustomChannel::class, AnotherTestCustomChannel::class]; } } class TestCustomChannel { public function send($notifiable, $notification) { $_SERVER['__notifiable.route'][] = $notifiable->routeNotificationFor('testchannel'); } } class AnotherTestCustomChannel { public function send($notifiable, $notification) { $_SERVER['__notifiable.route'][] = $notifiable->routeNotificationFor('anothertestchannel'); } }