dimanche 29 mars 2020

Laravel 5.6 testing Notification::assertSentTo() not found

Struggling since multiple days to get Notification::assertSentTo() method working in my feature test of reset password emails in a Laravel 5.6 app, yet receiving ongoing failures with following code:

namespace Tests\Feature;

use Tests\TestCase;
use Illuminate\Auth\Notifications\ResetPassword;
use Illuminate\Support\Facades\Notification;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;

class UserPasswordResetTest extends TestCase
{
   public function test_submit_password_reset_request()
   {
      $user = factory("App\User")->create();

      $this->followingRedirects()
         ->from(route('password.request'))
         ->post(route('password.email'), [ "email" => $user->email ]);

      Notification::assertSentTo($user, ResetPassword::class);
   }

}

I have tried several ideas including to use Illuminate\Support\Testing\Fakes\NotificationFake directly in the use list. In any attempt the tests keep failing with

Error: Call to undefined method Illuminate\Notifications\Channels\MailChannel::assertSentTo()

Looking forward to any hints helping towards a succesful test. Regards & take care!

Aucun commentaire:

Enregistrer un commentaire