Laravel's RefreshDatabase runs migrate:fresh once in every test process: every single-test run, every CI job and every --parallel worker. Refresher is an open-source drop-in replacement that does it once and reuses the result.
How it works
The first test process migrates (and seeds) the test database and saves it as a snapshot.
Every process after that restores the snapshot, until a migration, seeder or factory changes.
SQLite snapshots are a file copy; MySQL and MariaDB use mysqldump and the mysql client.
Setup
composer require amjadiqbal / refresher -- dev
// tests/Pest.php pest ( ) -> extend ( Tests \ TestCase :: class ) -> use ( AmjadIqbal \ Refresher \ Testing \ RefreshesWithRefresher :: class ) -> in ( 'Feature' ) ;
Enter fullscreen mode
Exit fullscreen mode
For PHPUnit, use the same trait in your test class. LazilyRefreshesWithRefresher replaces LazilyRefreshDatabase .…