Level 42
Feb 9, 2018
4
Level 11
How to test Email mock in laravel.
Here I'm trying to send a mail who are not registered within last date. When I'm trying to run this test case It is skipping email assertions and executing last assertion. Can you guys help me out on this? Thanks In advance. (Assume Last date is yesterday)
```$msg = [
'subject' => 'mail subject',
'body' => 'mail body',
'username' => '[email protected]'
];
$lateRegister = Register::where('last_date', '<=', \Carbon\Carbon::now())->get();
if(count($lateRegister) == 0){
$mock = Mockery::mock('Swift_Mailer');
$this->app['mailer']->setSwiftMailer($mock);
$mock->shouldReceive('send')->once
->andReturnUsing(function($msg)
{
$this->assertEquals('mail subject', $msg['subject'], 'Subject was not sent');
$this->assertEquals('[email protected]', $msg['username'], 'From Email id ');
$this->assertContains('mail body', $msg['body'], 'Im from email body');
});
}
$this->assertTrue(count($lateRegister) != 0);
}```
Please or to participate in this conversation.