Answer the question
In order to leave comments, you need to log in
Testing (PHPUnit) databases in Laravel - completely confused about the setup - how to figure it out?
For some reason, the Laravel documentation https://laravel.com/docs/8.x/database-testing assumes that I've only been doing database testing for two years now. But it's not. The topic of testing is quite fresh for me. So I don't understand at all:
1. Why should I do "Resetting The Database After Each Test"?
2. Why do I need to specify 'sqlite' and ':memory:' in phpunit.xml settings?
Even in version 5.4 there is such a feature:
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
Answer the question
In order to leave comments, you need to log in
In general, it turns out that the guide writers are too clever again :)
It is quite enough to put the line in the class definition:
Then the records in the database are simply rolled back - in the DatabaseTransactions trait this is implemented through a hook:
you can do without other frills.
In addition to this, you can use another copy of the main database purely for testing purposes.
use DatabaseTransactions;
beforeApplicationDestroyed()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question