mailer-test
mailer-test copied to clipboard
Add `SentEmailMixin::assertLastEmailSentTo()` (and rename `assertEmailSentTo()` to `assertFirstEmailSentTo()`
Hello!
currently SentEmailMixin::assertEmailSentTo does:
$this->sentEmails()
->ensureSome('No emails have been sent.')
->whereTo($expectedTo)
->ensureSome('No email was sent to "{expected}".', ['expected' => $expectedTo])
->first() //<-----
->call($callback)
;
checking the first() email that was sent to someone...
Though in general testing (or in my case)... I am interested in the most recent email.. so the last()..
This is not a bug... But by design, do we want last() instead of first() for that method?
Thank you :)
Hey @myselfhimself!
Interesting. This method is sort of intended as a quick and dirty solution. We can't change it's behaviour now as it would be a BC break. You could use the underlying code yourself in the test and change first() to last().
Alternatively, I'd be ok adding a SentEmailMixin::assertLastEmailSentTo() method. If we do, for consistency we should add SentEmailMixin::assertFirstEmailSentTo() and deprecate SentEmailMixin::assertEmailSentTo().
Hello Kevin, I let you decide :)
Le jeu. 27 oct. 2022 à 16:57, Kevin Bond @.***> a écrit :
Hey @myselfhimself https://github.com/myselfhimself!
Interesting. This method is sort of intended as a quick and dirty solution. We can't change it's behaviour now as it would be a BC break. You could use the underlying code yourself in the test and change first() to last().
Alternatively, I'd be ok adding a SentEmailMixin::assertLastEmailSentTo() method. If we do, for consistency we should add SentEmailMixin::assertFirstEmailSentTo() and deprecate SentEmailMixin::assertEmailSentTo().
— Reply to this email directly, view it on GitHub https://github.com/zenstruck/mailer-test/issues/17#issuecomment-1293652363, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJU5QUNQPLREZFZPT22JYLWFKJ6JANCNFSM6AAAAAARQB3MM4 . You are receiving this because you were mentioned.Message ID: @.***>
Ok, I'll leave this issue open as a feature request.
You could use the underlying code yourself in the test and change first() to last().
Were you able to do this to get your test passing?
I used:
$this->mailer()->sentEmails()
->whereTo($emailAddress)
->last()
->assertSubject($subject
);
and got my test passing.
Thank you