public function sendAuthCode_withUserObject_sendEmail()
{
//Stub the user object
$user = $this->createMock('Scheb\\TwoFactorBundle\\Model\\Email\\TwoFactorInterface');
$user->expects($this->any())->method('getEmail')->willReturn('[email protected]');
$user->expects($this->any())->method('getEmailAuthCode')->willReturn(1234);
$messageValidator = function ($subject) {
/* @var \Swift_Message $subject */
return key($subject->getTo()) === '[email protected]' && $subject->getFrom() === array('[email protected]' => 'Sender Name') && $subject->getSubject() === 'Authentication Code' && $subject->getBody() === 1234;
};
//Expect mail to be sent
$this->swiftMailer->expects($this->once())->method('send')->with($this->logicalAnd($this->isInstanceof('Swift_Message'), $this->callback($messageValidator)));
$this->mailer->sendAuthCode($user);
}