Skip to content

Instantly share code, notes, and snippets.

@mbpating
Created January 5, 2022 08:09
Show Gist options
  • Save mbpating/9b4cd5fc03934619c28fe757a9f981ac to your computer and use it in GitHub Desktop.
Save mbpating/9b4cd5fc03934619c28fe757a9f981ac 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\Unit;
use PHPUnit\Framework\TestCase;
use Illuminate\Support\Facades\Mail;
class CustomerStoreTest extends TestCase
{
public function test_customer_can_be_stored()
{
Mail::fake();
$customerData = [
'name' => 'Mark Berlon A. Pating',
'email' => 'mbpating@gmail.com'
];
$this->json('POST','/customer',$customerData,['Accept' => 'application/json'])
->assertStatus(201)
->assertJsonStructure([
'saved' => true
]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment