I have a problem with a unit test not passing. The app loads users from a csv and sends a welcome email.
This is my test:
/** @test */
public function test_a_welcome_email_is_sent_when_a_user_is_loaded()
{
Mail::fake();
Mail::assertNothingQueued();
$this->loadUsers();
Mail::assertQueued(Welcome::class);
}
loadUsers() imports users into the database and dispatches a job for each user:
<?php
namespace App\Jobs;
...
class SendWelcomeEmail implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
private User $user;
public function __construct(User $user)
{
$this->user = $user;
}
public function handle()
{
Mail::to($this->user->email)->send(new Welcome($this->user));
}
}
However when I run the tests I get the following:
1) Tests\Feature\LoadUsersTest::test_a_welcome_email_is_sent_when_a_user_is_loaded
The expected [App\Mail\Welcome] mailable was not queued.
Failed asserting that false is true.