Skip to content

Instantly share code, notes, and snippets.

@komatzz
Created October 12, 2017 09:34
Show Gist options
  • Select an option

  • Save komatzz/8bfee6d2346820d25c2b903fc55b4318 to your computer and use it in GitHub Desktop.

Select an option

Save komatzz/8bfee6d2346820d25c2b903fc55b4318 to your computer and use it in GitHub Desktop.
Laravel でモックを使ったメール送信のテストが簡単だった ref: http://qiita.com/komatzz/items/111b71467a2f27c9bb43
class MailTest extends TestCase
{
public function testMailSend()
{
Mail::fake();
$email = 'test@gmail.com';
// 任意の実際のリクエスト処理
$this->put(
"test/mail",
[
'mail_to' => $email,
]
);
// 1回送信されたことをアサート
Mail::assertQueued(MailBuilder::class, 1);
// メールが指定したユーザーに送信されていることをアサート
Mail::assertQueued(
MailBuilder::class,
function ($mail) use ($email) {
return $mail->to[0]['address'] === $email;
}
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment