Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SentEmailMixin::assertLastEmailSentTo() (and rename assertEmailSentTo() to assertFirstEmailSentTo() #17

Open
myselfhimself opened this issue Oct 27, 2022 · 4 comments
Labels
enhancement New feature or request

Comments

@myselfhimself
Copy link

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 :)

@kbond
Copy link
Member

kbond commented Oct 27, 2022

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().

@myselfhimself
Copy link
Author

myselfhimself commented Oct 27, 2022 via email

@kbond
Copy link
Member

kbond commented Oct 27, 2022

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?

@kbond kbond changed the title assertEmailSentTo relies on first email to someone instead of last Add SentEmailMixin::assertLastEmailSentTo() (and rename assertEmailSentTo() to assertFirstEmailSentTo() Oct 27, 2022
@kbond kbond added the enhancement New feature or request label Oct 27, 2022
@myselfhimself
Copy link
Author

myselfhimself commented Oct 28, 2022

I used:

        $this->mailer()->sentEmails()
            ->whereTo($emailAddress)
            ->last()
            ->assertSubject($subject
            );

and got my test passing.

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

No branches or pull requests

2 participants