nbbfv's avatar
Level 2

how to test that mail body contains some text?

how can I test if mail body contains a link for example? I use laravel 5.3

public function we_can_send_email_verification_email_to_existing_player()
    {
        Mail::fake();

        // Given if I have an admin User
        $admin = factory(User::class)->create();

        // And a Player
        $player = factory(Player::class)->create();

        // When Admin is logged in and visits the Player's profile page
        $this->actingAs($admin)
            ->visitRoute('players.show', ['player' => $player->f_id])
            ->see($player->f_name)
            ->see('Resend email verification request');

        // If he clicks on Resend email verification request we should see proper response
        $this->json('POST', "players/".$player->f_id."/send-email-verification", [])
            ->seeJsonEquals(['success' => true]);

        Mail::assertSent(EmailValidationEmail::class, function ($mail) use ($player) {
            return $mail->player->f_id === $player->f_id;
        });

        // Assert a message was sent to the given users...
        Mail::assertSentTo([$player->f_mail], EmailValidationEmail::class);

    }
0 likes
2 replies
nbbfv's avatar
Level 2

thanks ohffs for the info.

1 like

Please or to participate in this conversation.