successdav's avatar

Mail test not passing

I am following up a laracast video on sending mails but my test is not passing...

My test class

use DatabaseMigrations;
    
    /** @test */
    public function a_comfirmation_email_is_sent_upon_registration()
    {
        Mail::fake();
        
        event(new Registered(create('App\User')));

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

Event Service Provider Class

 protected $listen = [
        'App\Events\ThreadHasNewReply' => [
            'App\Listeners\NotifyThreadSubscribers',
        ],

        Registered::class => [
            'App\Listeners\SendEmailConfirmationRequest'
        ]
    ];

My SendEmailConfirmationRequest Class

   public function handle(Registered $event)
    {
        Mail::to($event->user)->send(new PleaseConfirmYourEmail());
    }

and when I run this test it just returns

1) Tests\Feature\RegistrationTest::a_comfirmation_email_is_sent_upon_registration
The expected [App\Mail\PleaseConfirmYourEmail] mailable was not sent.
Failed asserting that false is true.

0 likes
3 replies
D9705996's avatar
D9705996
Best Answer
Level 51

Have you tried firing your event through php artisan tinker? Does this send your email? If so then theres an issue with the test otherwise your event is the problem

successdav's avatar

I have not, can you please show me how fire this event from tinker

Please or to participate in this conversation.