/
githubmirror
/
framework
Обзор
Документация
Войти
/
githubmirror
/
framework
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
13.x
tests/Integration/Mail/SentMessageMailTest.php
83 строки
2 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\Mail; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Schema\Blueprint; use Illuminate\Foundation\Testing\LazilyRefreshDatabase; use Illuminate\Notifications\Events\NotificationSent; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Notifiable; use Illuminate\Notifications\Notification; use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Schema; use Orchestra\Testbench\TestCase; class SentMessageMailTest extends TestCase { use LazilyRefreshDatabase; protected function afterRefreshingDatabase() { Schema::create('sent_message_users', function (Blueprint $table) { $table->increments('id'); }); } protected function beforeRefreshingDatabase() { Schema::dropIfExists('sent_message_users'); } public function testDispatchesNotificationSent() { $notificationWasSent = false; $user = SentMessageUser::create(); Event::listen( NotificationSent::class, function (NotificationSent $notification) use (&$notificationWasSent, $user) { $notificationWasSent = true; /** * Confirm that NotificationSent can be serialized/unserialized as * will happen if the listener implements ShouldQueue. */ /** @var NotificationSent $afterSerialization */ $afterSerialization = unserialize(serialize($notification)); $this->assertTrue($user->is($afterSerialization->notifiable)); $this->assertEqualsCanonicalizing($notification->notification, $afterSerialization->notification); }); $user->notify(new SentMessageMailNotification()); $this->assertTrue($notificationWasSent); } } class SentMessageUser extends Model { use Notifiable; public $timestamps = false; } class SentMessageMailNotification extends Notification { public function via(): array { return ['mail']; } public function toMail(object $notifiable): MailMessage { return (new MailMessage) ->line('Example notification with attachment.') ->attach(__DIR__.'/Fixtures/blank_document.pdf', [ 'as' => 'blank_document.pdf', 'mime' => 'application/pdf', ]); } }