Laravel test email was sent with delay

Viewed 30

Is it possible to write a test to make sure an email was sent that has a delay on it? I am able to test that it has been pushed to the queue, but i would like to make sure that the logic in the mailer send the correct email. This is what i have, the assertPushed works, but the assertSent returns a fail.

This is how i am running the job in the controller;

ProcessEmailJob::dispatch($this, $user)
    ->delay(now()->addMinutes(10));

This is the test

Queue::fake();
Mail::fake();

// processing here

Queue::assertPushed(ProcessEmailJob::class, function ($job) {
    return ! is_null($job->delay);
});

Mail::assertSent(EmailUserMail::class);
1 Answers

Use sleep(10 * 60) inside your job handler and remove the delay from the controller code.

Related