X
X
XY2018-04-29 15:01:03
Unit testing
XY, 2018-04-29 15:01:03

How to delete data from table after test execution?

How in phpunit can I clear a table in the test database after each test?
Tried to use: Illuminate\Foundation\Testing\RefreshDatabase (laravel testing tool), but this trait clears the database only after all tests are completed, i.e. it turns out that at performance of each test, in tables there are data from other tests.
Is it possible to do something with this or do I need to delete the test data myself?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
hakkol, 2018-04-29
@hakkol

In TestCase.php I use

public function setUp()
{
    parent::setUp();

    \Artisan::call('migrate:refresh');
    \Artisan::call('db:seed', ['--class' => 'TestDatabaseSeeder', '--database' => 'testing']);
}

Then, before each test, the base will return to its original value.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question