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

ckalita's avatar

Asserting Mailable is sent from Notification

I am at a loss for something apparently quite obvious. I am testing a Notification class to ensure it sends a Mail message, which is not queued.

My Event/Listener pubsub triggers Notification, Notification sends a Mailable.

  • I have verified event is registered and listened upon (test for events, not shown here)
  • i have verified the listener triggers the notification (listener test, works)
    /** @test */
    public function it_will_handle_signed_event_with_countersigner()
    {
		Notification::fake();

        $model = $this->factory(Contract::class)
            ->signed()
            ->withCountersigner()
            ->create();

        $event = new Signed($model);
        $listener = new SignedListener();

        $listener->handle($event);

        Notification::assertSentTo(
				$model->countersigner, 
				RequestClientSignatureNotification::class
        );
    }
  • now i want to make sure that notification successfully triggers the email, hence:
    /** @test */
    public function it_will_handle_request_client_signature_notification()
    {
        Mail::fake();

        $profile = $this->factory(Profile::class)->create();

        $contracts = Event::fakeFor(fn() =>
            $this->factory(Contract::class)->signed()->for($profile, 'countersigner')->count(2)->create()
        );

        Notification::send($profile, new RequestClientSignatureNotification($contracts));

        Mail::assertSent(RequestClientSignatureEmail::class);
    }

but no matter how i try to test it, either via facad'ing though Notification (which I assume would be the proper way for the test) or via $profile->notify(..) or even with $notification->toMail(..) - in all cases it return false; with identical code run in tinker - it sure sends.

I am sure that I am missing something extremely obvious

0 likes
1 reply
kevinbui's avatar

Can you show the code in that RequestClientSignatureEmail class?

Please or to participate in this conversation.