我正在尝试发送一封测试电子邮件并断言(使用事件)它已发送。
测试运行良好并且事件实际上发生了(我在 LogSendingMessage 类上记录事件处理程序方法),但从不断言expectsEvents
,既不在之前,也不在Mail::send
方法之后。
public function testSendSimpleMailOverSMTP()
{
// Send methods
$fromMail = 'my@mail.com';
$fromName = 'Tiago Gouvêa';
$toMail = 'myanother@mail.com';
$toName = 'Tiago Gouvêa';
$subject = 'Mail testing123';
$view = 'SimpleMail';
$data = array('body' => "Olá fulano");
$this->expectsEvents(Illuminate\Mail\Events\MessageSending::class);
$this->expectsEvents(Illuminate\Mail\Events\MessageSent::class);
Mail::send($view, $data, function (Illuminate\Mail\Message $message) use ($toMail, $toName, $fromMail, $fromName, $subject) {
$message->to($toMail, $toName)->subject($subject);
$message->from($fromMail, $fromName);
});
}
Here on stack 还有一些类似的问题,但是,没有一个对我有用。我很感激任何帮助。:)