Mailgun icon indicating copy to clipboard operation
Mailgun copied to clipboard

Support mocking

Open tpalts opened this issue 7 years ago • 3 comments

Similar to faking Laravel's Mail, the Mailgun facade should be fakeable:

public function test_it_sends_email()
{
    Mailgun::fake();

    // any action that triggers sending mail through Bogardo/Mailgun package
    $this->visit('/send-mail')
->press('Send!')

    Mailgun::assertSent('mail.batch', function ($mail) use ($userA,$userB) {
        return $mail->hasTo($userA->email, $userB->email) &&
            $mail->hasCc('...') &&
            $mail->isBcc('...') &&
            $mail->isBcc('...');
        });
}

tpalts avatar May 03 '17 14:05 tpalts

At the moment I'm using Mailgun postbin to retrieve content and test against it, but is very slow. Would be amazing if it could support mocking. Despite the fact that mailgun allows test mode, it doesn't help testing the mail data.

cosmini avatar Oct 16 '19 22:10 cosmini

@cosmini Couldn't you just mock the HTTP client? https://github.com/Bogardo/Mailgun#http-client-dependency

Bogardo avatar Oct 16 '19 22:10 Bogardo

i've tried to do something similar to what's in the library test case: https://github.com/Bogardo/Mailgun/blob/master/tests/MailgunTestCase.php#L21

But I've got a whole new set of errors.

Perhaps it is possible to achieve this in other ways, but I'm using this library for convenience and to save time in development, having an easy way to test it would be a plus.

Thanks.

cosmini avatar Oct 16 '19 23:10 cosmini