Summer Sale! All accounts are 50% off this week.

netdjw's avatar
Level 15

Notification::send() not queued

I my unit test I try to test the notification should queued on "email" queue.

This is my test code:

    /** @test */
    public function shouldQueueMail(): void
    {
        Queue::fake();

        // ... prepare datas
        $notification = new FormFilledNotification($to, $subject, $formData);

        $notifiable = new Form();

        $formMail = $notification->toMail($notifiable);

        Notification::send($notifiable, $notification);

        Queue::assertPushed(FormMail::class);
    }

And I get this error:

ReflectionException: Method ...\FormMail::__invoke() does not exist

That is actually true, but I don't understand why I get this message.

I tried to use Queue::spy() and it say:

RuntimeException: Queue resolver did not return a Queue implementation.

The FormMail looks like this:

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Spatie\MailTemplates\Interfaces\MailTemplateInterface;
use Spatie\MailTemplates\TemplateMailable;

class FormMail extends TemplateMailable implements Mailable
{
    use Queueable;
    use SerializesModels;

    protected static $templateModelClass = EmailTemplate::class;

    public $details = '';

    public Form $form;

    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct(array $form_data, Form $form)
    {
        $this->form = $form;

        $this->details = (new FormDetailsMailComponent($form_data))
            ->render();
    }

    protected function resolveTemplateModel(): MailTemplateInterface
    {
        return $this->mailTemplate = $this->form->emailTemplate()->first()
            ?? EmailTemplate::whereCode(EmailTemplateCodesEnum::FORM_SENT)->first();
    }
}

So what I miss to run after Notification::send()?

0 likes
10 replies
netdjw's avatar
Level 15

@vincent15000 thank you! I read the documentation, and there isn't any detail about what I miss. I do the same as the doc say. Could you please give me any details what I miss?

1 like
ousid's avatar

Have you tried to use ShouldQueue interface in the mail class? I think you are missing the interface...

1 like
netdjw's avatar
Level 15

@ousid I added it, now the code is:

class FormMail extends TemplateMailable implements Mailable, ShouldQueue
{

And the test result is still RuntimeException: Queue resolver did not return a Queue implementation.

1 like
ousid's avatar

@netdjw Are you sure that you are pulling the correct namespace? (Illuminate\Support\Facades\Queue)

1 like
netdjw's avatar
Level 15

@ousid Yes, this is the code: use Illuminate\Support\Facades\Queue;

1 like
ousid's avatar

@netdjw That's weird! Because this error, occur when you are not implementing the right queue facade.

Have you tried to clear the cache?

1 like
netdjw's avatar
Level 15

@ousid Yes, cache:clear, route:clear, config:clear, view:clear all run, and still the same error.

...and I think there is a testing bug, or I miss run something in my test, but I don't know what I miss.

Please or to participate in this conversation.