Event listener never asserts while testing on Laravel / PHPUnit

608 Views Asked by At

I'm trying to send a test email and assert (using events) that it was sent.

The test runs fine and the event in fact happen (I'm logging the event handler method on LogSendingMessage class), but the expectsEvents never assert, neither before, neither after the Mail::send method.

public function testSendSimpleMailOverSMTP()
{
    // Send methods
    $fromMail = '[email protected]';
    $fromName = 'Tiago Gouvêa';
    $toMail = '[email protected]';
    $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 has another questions some like, but, none of then worked for me. I appreciate any help. :)

0

There are 0 best solutions below