Skip to content

Instantly share code, notes, and snippets.

@jekingohel
Created January 6, 2022 09:43
Show Gist options
  • Save jekingohel/d91f43bd0d26d46f1029d3c023136b15 to your computer and use it in GitHub Desktop.
Save jekingohel/d91f43bd0d26d46f1029d3c023136b15 to your computer and use it in GitHub Desktop.
Using laravel's HTTP tests, test the CustomerController's store method, make sure to mock the mailable "WelcomeNewCustomer" using mail-fake.
<?php
namespace Tests\Feature;
use Tests\TestCase;
use App\Mail\WelcomeNewCustomer;
use Illuminate\Support\Facades\Mail;
class StoreCustomer extends TestCase
{
/**
* A basic feature test example.
*
* @return void
*/
public function test_store_customer()
{
Mail::fake();
$data = [
'name' => $this->faker->name,
'email' => $this->faker->email,
];
$response = $this->post(route('customer.store'), $data);
Mail::assertNothingSent();
Mail::assertSent(WelcomeNewCustomer::class);
$response->assertStatus(201)->assertJson($data);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment