While investigating ways to speed up tests by Chris Duell
and Jordan Eldredge. I stumbled upon an
alternative way which might not be as fast but is easy to implement.
If you are using a Sqlite in-memory database during your tests and the cause of your
speed issues is your migrations. You can gain a 50% speed increase by avoiding the DatabaseMigrations trait and implementing
The DatabaseMigrations trait
uses the phpunit @before
annotation to execute a function before each test. The function runs the “migrate” command and adds a hook to run the
“mirgate:rollback” command when the test is finished. But because we are using a in-memory database, the database is destroyed
and created with every new database connection. This means we can save time by not rolling back the migrations at the end of
To implement migrations without rollbacks you have to do the following.
Add the in-memory sqlite config to your connections array
Set your tests to run against sqlite database by adding a env variable