Created
January 6, 2022 09:43
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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