Abhiraj Tulsyan
Abhiraj Tulsyan

Reputation: 123

Notification fake assertion not working on password reset test?

I was trying to make tests for my auth routes. For password reset route I am trying to make in which I am faking the notification module of laravel and asserting as per the docs. This is my test file

 public function testUserReceivesAnEmailWithAPasswordResetLink()
    {
        $this->withoutExceptionHandling();
        Notification::fake();

        $user = factory(User::class)->make();

        $response = $this->post($this->passwordEmailPostRoute(), [
            'email' => $user->email,
        ]);

        $this->assertNotNull($token = DB::table('password_resets')->where('email', $user->email));

        Notification::assertSentTo($user, PasswordReset::class);

    }

While I am running this, I am getting notification was not sent error.

My User model is like this:

 use Notifiable, HasApiTokens, SoftDeletes, Uuidable, Switchable, ResourceMapper;

 public function role()
    {
        return $this->belongsTo('App\Models\Role');
    }

    public function company()
    {
        return $this->belongsTo('App\Models\Company');
    }

    public function AauthAccessToken()
    {
        return $this->hasMany('App\Models\OauthAccessToken');
    }

    public function isRole($role)
    {
        return $this->role->uuid == $role;
    }

    public function sendPasswordResetNotification($token)
    {
        $this->notify(new PasswordReset($token));
    }

    public function resource()
    {
        return $this->morphTo();
    }

I can't figure whats the exact problem.

Upvotes: 1

Views: 259

Answers (1)

Armin
Armin

Reputation: 2562

Since you are overwriting sendPasswordResetNotification inside your User model, then make sure both User.php and test file, are using the same PasswordReset class.

Upvotes: 0

Related Questions