Bogardo / Mailgun

Mailgun package for Laravel
MIT License
295 stars 115 forks source link

Support mocking #114

Open tpalts opened 7 years ago

tpalts commented 7 years ago

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('...');
        });
}
cosmini commented 5 years ago

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.

Bogardo commented 5 years ago

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

cosmini commented 5 years ago

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.