whatdafox/codeception-mailtrap

Assert against any email in the mailbox

polevaultweb opened this issue · 2 comments

@foxted what do you think about enhancing the 'see' assertions so we can look in X last emails.

My use case is testing a process that sends 2 emails at the same time, but at the moment I can only see the last message to run assertions against.

So instead of:

public function seeInEmailHtmlBody($expected)
    {
        $email = $this->fetchLastMessage();
        $this->assertContains($expected, $email['html_body'], 'Email body contains HTML');
    }

We do

public function seeInEmailHtmlBody($expected, $numberOfMessages = 1)
    {
        $email = $this->fetchLastMessages(numberOfMessages);
        $this->assertContains($expected, $email['html_body'], 'Email body contains HTML');
    }

This way the default is still the last message but we can look in a range of mails to assert one exists based on certain criteria.

@foxted happy to raise a PR 😄

Seem like a valid use case, sure! :)