Laravel unit testing emails

前端 未结 8 1398
难免孤独
难免孤独 2021-02-20 10:12

My system sends a couple of important emails. What is the best way to unit test that?

I see you can put it in pretend mode and it goes in the log. Is there something t

8条回答
  •  执笔经年
    2021-02-20 10:57

    If you just don't want the e-mails be really send, you can turn off them using the "Mail::pretend(true)"

    class TestCase extends Illuminate\Foundation\Testing\TestCase {
        private function prepareForTests() {
          // e-mail will look like will be send but it is just pretending
          Mail::pretend(true);
          // if you want to test the routes
          Route::enableFilters();
        }
    }
    
    class MyTest extends TestCase {
        public function testEmail() {
          // be happy
        }
    }
    

提交回复
热议问题