Skip to content

Instantly share code, notes, and snippets.

@RomikMakavana
Created November 19, 2021 10:36
Show Gist options
  • Save RomikMakavana/587fc593db821ccffa177c679a408ee2 to your computer and use it in GitHub Desktop.
Save RomikMakavana/587fc593db821ccffa177c679a408ee2 to your computer and use it in GitHub Desktop.
Laravel Mail Unit Testing
<?php
namespace Tests\Feature;
use App\Mail\OrderShipped;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Support\Facades\Mail;
use Tests\TestCase;
class UserRegisterTest extends TestCase
{
public function test_user_register()
{
Mail::fake();
// Perform order shipping...
// Assert that no mailables were sent...
Mail::assertNothingSent();
// Assert that a mailable was sent...
Mail::assertSent(EmailVerification::class);
// Assert a mailable was sent twice...
Mail::assertSent(EmailVerification::class, 2);
// Assert a mailable was not sent...
Mail::assertNotSent(AnotherMailable::class);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment