我正在测试应用程序中的通知,这是我的代码,用于测试Admin是否收到通知:
public function testAdminReceivesNotifications()
{
Notification::fake();
$admin = $this->preload();
$taskTitle = str_random();
$project = Project::first();
$projectMember = factory(\App\Models\User::class)->create([
'type' => 'INTERNAL'
]);
$project->users()->save($projectMember, [
'project_permissions' => [1,2,3,4,5,6,7,8,10]
]);
$this->browse(function (Browser $browser, Browser $secondBrowser) use($admin, $taskTitle, $project, $projectMember) {
$this->login($browser, $admin)
->visit("p/{$project->slug}")
->waitForText('Add Task')
->click("@add-task")
->waitForText('Create Task')
->type('@task-title', $taskTitle)
->keys('[trix-id="1"]', str_random())
->press('SAVE TASK')
->waitForText('Post anyway')
->press('Post anyway')
->waitForText('Unscheduled')
->pause(1000)
->assertSee('Unscheduled')
->assertSee($taskTitle);
$task = Project\Todo::where('title', $taskTitle)->first();
$this->login($secondBrowser, $projectMember)
->visit("p/{$project->slug}/tasks/{$task->id}")
->waitForText($task->title)
->keys('trix-editor', str_random() . "message by another member")
->press('Reply')
->pause(2000);
});
Notification::assertSentTo($admin,TodoMessageCreated::class);
}
我遇到的问题-即使我确实将通知设置为假-发送电子邮件(我在测试中将日志用作邮件驱动程序,并且在日志中看到了电子邮件。我已经检查过-我可以保证触发TodoMessageCreated。