Test Mail and number of emails send

Posted 7 months ago by longestdrive


My Laravel 5.5 testing journey continues

How do I test how many emails were sent by my test.

I'm trying to test that multiple emails were sent in a test. The method I'm testing against is only sending to the first recipient so I need to find a way of building a test

My current test is this:

    public function testUserCanSendBroadcastMessageToMultiplePlayers()


    factory(Player::class, 4)->create();

    $players = Player::get()->pluck('id')->toArray();

    $request = [
        'subject'=>"test subject",
        'message'=>'test message'

    $response = $this->actingAs($this->user)
        ->call('POST', 'broadcast/create', $request);

    $subject = "test subject";
    $message = "test message";

    Mail::assertSent(NewBroadcastMessage::class, function ($mail) use ($subject, $message) {
        return $mail->subject === $subject;

I don't know where I should count() the emails sent. H

How do I build my test correctly?

Please sign in or create an account to participate in this conversation.