Skip to content

Instantly share code, notes, and snippets.

@abdullahnaseer
Created January 2, 2022 10:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abdullahnaseer/acfccd62b753af03b922b33292b5770c to your computer and use it in GitHub Desktop.
Save abdullahnaseer/acfccd62b753af03b922b33292b5770c to your computer and use it in GitHub Desktop.
Customer Store Test - Evaluation of Laravel
<?php
namespace Tests\Unit;
use App\Mail\WelcomeNewCustomer;
use Tests\TestCase;
use Illuminate\Support\Facades\Mail;
class CustomerStoreTest extends TestCase
{
/**
* Test Validation rules.
*
* @return void
*/
public function test_it_requires_name_and_email_on_store_request()
{
$response = $this->postJson('/api/customer', [
'name' => "",
'email' => "",
]);
$response->assertStatus(422)
->assertInvalid(['name', 'email']);
}
/**
* Test Customer Creation
*
* @return void
*/
public function test_it_creates_a_new_customer_on_store_request()
{
Mail::fake();
$response = $this->postJson('/api/customer', [
'name' => "Test",
'email' => "test@example.com",
]);
$response->assertStatus(200)
->assertJson([
'saved' => true,
]);
Mail::assertSent(WelcomeNewCustomer::class);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment