Created
October 12, 2017 09:34
-
-
Save komatzz/8bfee6d2346820d25c2b903fc55b4318 to your computer and use it in GitHub Desktop.
Laravel でモックを使ったメール送信のテストが簡単だった ref: http://qiita.com/komatzz/items/111b71467a2f27c9bb43
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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