nunomaduro / laravel-mojito

🍹 A lightweight package for testing Laravel views in isolation
http://nunomaduro.com/
MIT License
373 stars 16 forks source link

[Feature] Apply View Assertions to Mailables and Notifications #13

Open peterfox opened 4 years ago

peterfox commented 4 years ago

I've been playing with the concept that it might be useful to use the view assertions with notification emails and mailables when doing assertions on them in tests, giving devs the ability to render them and perform further assertions on the content produced.

An example of how this would work as an API would be:

Notifications::fake();

$user->notify(new Example());

Notification::assertSentTo($user, ViewAssertion::make(function (ViewAssertion $assertion) {
    $assertion->contains('Hello World');

    return true;
}); 
Mail::fake();

(new ExampleMailable)->send();

Mail::assertSent(ExampleMailable::class, ViewAssertion::make(function (ViewAssertion $assertion) {
    $assertion->contains('Hello World');

    return true;
});

I already have a rough but working implementation if you think it'd be worth while adding to Mojito?

nunomaduro commented 4 years ago

Sure. Make a pull request, and update the docs.