laravel / framework

The Laravel Framework.
https://laravel.com
MIT License
32.51k stars 11.02k forks source link

Mail fake testing doesn't work without using the 'to' method #16242

Closed splatEric closed 8 years ago

splatEric commented 8 years ago

Description:

When using a Mailable that manages it's recipient directly, the Mail::assertSent(Mailable::class) method does not detect that the Mailable was sent.

Steps To Reproduce:


class MyMailable extends Mailable
{
...
public function build()
{
    return $this->view('views.email.mymailable')
        ->to($this->user->email);
}

...

public function testMailableFailing()
{
    Mail::fake();
    $user = factory(App\User::class, 1)->make();
    $mailable = new MyMailable($user);

    Mail::send($mailable);

    Mail::assertSent(MyMailable::class); // fails
}

public function testMailablePasses()
{
    Mail::fake();
    $user = factory(App\User::class, 1)->make();
    $mailable = new MyMailable($user);

    Mail::to($user)->send($mailable);

    Mail::assertSent(MyMailable::class); // passes
}
themsaid commented 8 years ago

PR submitted with a fix: https://github.com/laravel/framework/pull/16248