laravel / ideas

Issues board used for Laravel internals discussions.
938 stars 28 forks source link

[Proposal] Easier testing of rendered email contents #1809

Open ohnotnow opened 5 years ago

ohnotnow commented 5 years ago

There have been previous discussions about this - for instance https://github.com/laravel/ideas/issues/405 .

I'm proposing adding a couple of additional methods onto the mail fake to make it easier to check the finally rendered contents match your expectations. We have to send a lot of mails and on occasion we've had issues where the right values have been passed to mailables, but the template used them incorrectly leading to a lot of confusion.

At the moment we're manually checking them and/or using some of the work-arounds given in the discussion linked above. It would be a lot cleaner if we could do something along the lines of :

Mail::fake();
...
Mail::assertSent(SomeEmail::class, function ($mail) use ($normalPerson, $importantPerson, $interview) {
    return $mail->hasText("Dear {$normalPerson}") &&
        $mail->hasText("interview with {$importantPerson}") &&
        $mail->hasText("on " . $interview->start->format('d/m/Y');
});
anatoliyarkhipov commented 4 years ago

@ohnotnow Do you have example implementation for such methods?

ohnotnow commented 4 years ago

@anatoliyarkhipov no - the idea didn't get much traction so I haven't really looked into it more I'm afraid.