@jrdavidson Just fake the mailer and test the expected mail was queued:
Mail::fake();
$admin = Administrator::factory()->create();
$this
->actingAs($admin)
->post(route('teachers.store'), $this->attributes)
->assertSessionHasNoErrors()
->assertRedirect();
$teacher = Teacher::first();
Mail::assertQueued(WelcomeTeacher::class, function (WelcomeTeacher $mail) use ($teacher) {
return (
$mail->teacher->is($teacher) &&
$mail->hasTo($teacher->email) &&
$mail->hasTo($teacher->school_email)
);
});
Don’t test that the listener is hooked up to the event, otherwise you’re then testing how your code is written and not what your code is doing. If you refactor your code so that it does the same thing but in a different way, then your test would start failing, even though nothing’s “broken”.