Skip to content

Instantly share code, notes, and snippets.

@minthemiddle
Created September 17, 2019 12:06
Show Gist options
  • Save minthemiddle/47691999632a2ee85cbfc962bd03849b to your computer and use it in GitHub Desktop.
Save minthemiddle/47691999632a2ee85cbfc962bd03849b to your computer and use it in GitHub Desktop.
Laravel Test Stub
<?php
namespace Tests\Feature;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
use App\User;
class ExampleTest extends TestCase
{
use RefreshDatabase;
/** @test */
public function testExample()
{
$this->withoutExceptionHandling();
$this->markTestIncomplete();
$response = $this->get('/');
$response->assertStatus(200);
}
/** @test */
public function testExampleWithVerifiedUser()
{
$this->withoutExceptionHandling();
$this->markTestIncomplete();
$user = factory(User::class)->make();
$response = $this->actingAs('user')->get('/');
$response->assertStatus(200);
}
/** @test */
public function testExampleWithUnverifiedUser()
{
$this->withoutExceptionHandling();
$this->markTestIncomplete();
$user = factory(User::class)->make([
'email_verified_at' => null,
]);
$response = $this->actingAs('user')->get('/');
$response->assertStatus(200);
}
}
@minthemiddle
Copy link
Author

minthemiddle commented Sep 17, 2019

  • This can be used as a replacement for the default stub that php artisan make:test uses
  • Depends on laravel-stubs
  • It seems easier to me to delete than to add over and over

Features

  • The common cases of verified and unverified users
  • Disable Laravel's exception handling
  • Mark all tests as incomplete
  • Use database migrations
  • Use short /** @test */ by default

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment