Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Oct 5, 2021
1 parent ac66830 commit 68f2d0d
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions database-testing.md
Expand Up @@ -28,18 +28,31 @@ Laravel provides a variety of helpful tools and assertions to make it easier to
<a name="resetting-the-database-after-each-test"></a>
### Resetting The Database After Each Test

Before proceeding much further, let's discuss how to reset your database after each of your tests so that data from a previous test does not interfere with subsequent tests. Laravel's included `Illuminate\Foundation\Testing\LazilyRefreshDatabase` trait will take care of this for you. This trait is already included on your application's base `TestCase` class so that you may always assume you have a fresh copy of your database during each of your application's "feature" tests:
Before proceeding much further, let's discuss how to reset your database after each of your tests so that data from a previous test does not interfere with subsequent tests. Laravel's included `Illuminate\Foundation\Testing\RefreshDatabase` trait will take care of this for you. Simply use the trait on your test class:

<?php

namespace Tests;
namespace Tests\Feature;

use Illuminate\Foundation\Testing\LazilyRefreshDatabase;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Tests\TestCase;

abstract class TestCase extends BaseTestCase
class ExampleTest extends TestCase
{
use CreatesApplication, LazilyRefreshDatabase;
use RefreshDatabase;

/**
* A basic functional test example.
*
* @return void
*/
public function test_basic_example()
{
$response = $this->get('/');

// ...
}
}

<a name="defining-model-factories"></a>
Expand Down

0 comments on commit 68f2d0d

Please sign in to comment.