RefreshDatabase running migrate:fresh once per test suite #41750
Replies: 3 comments
-
I am facing the same problem. My schema is up to date and migrate:fresh is executed every time I run tests. It results in database wipe on every run. |
Beta Was this translation helpful? Give feedback.
-
I have the same issue. Anyone aware this has been resolved? (laravel 9). I found a package at https://github.com/PlannrCrm/laravel-fast-refresh-database who wrote an alternative for the refreshdatabase trait that is 'smart' |
Beta Was this translation helpful? Give feedback.
-
Being your schema should not be modified at run time, the ideal setup I am looking for is:
I am finding this difficult to implement with a multi database instance architecture. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello all,
I'm trying to understand the RefreshDatabase trait and how it uses migrations. I read in the documentation that:
"The Illuminate\Foundation\Testing\RefreshDatabase trait does not migrate your database if your schema is up to date."
https://laravel.com/docs/9.x/database-testing#resetting-the-database-after-each-test
Based off what I'm seeing in my project and looking at the source code, it looks like the database is migrated with
artisan migrate:fresh
, although only once per run of the test suite.framework/src/Illuminate/Foundation/Testing/RefreshDatabase.php
Line 70 in b9203fc
The migration is conditional on the
RefreshDatabaseState::$migrated
flag, but it doesn't look like the application ever sets that value before running the migrations the first time.Is this the intended behavior? If so, the documentation seems kind of misleading here. Maybe it should read:
"The Illuminate\Foundation\Testing\RefreshDatabase trait will migrate (migrate:fresh) your database only once per run of the test suite."
Beta Was this translation helpful? Give feedback.
All reactions