G
G
Gleb Starkov2020-06-20 17:46:27
Laravel
Gleb Starkov, 2020-06-20 17:46:27

Why is the database cleared after each method in PHPUnit?

I'm testing the API. Laravel 7.
In one method I register and authenticate the user.
In another, you need to work with a previously created user.
But the DB is cleared in the second method and the user is no more.

You can, of course, write everything in one method, but this is wrong.
Previously worked in PHPUnit in Laravel 5, there were no such problems.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alex Wells, 2020-06-20
@colonel

Tests should not be dependent on each other. Nothing has changed since Laravel 5 - you either added the DatabaseMigrations or the DatabaseTransactions trait. Anyway, leave everything as it is and write normal tests.

A
adam_carraway, 2020-06-20
@adam_carraway

You can use another database for testing. Google the phpunit.xml setup for testing

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question