Never run your test suite against a live database
Useful
1 min read
Laravel's RefreshDatabase trait is wonderful in a test environment and destructive anywhere else. If your config doesn't force tests onto a separate database, the suite will happily wipe whatever the .env points to.
I learned this the expensive way, and now it's a rule: before running tests on any deployed site or any copy that shares its environment file, I verify which database they'll hit. Check phpunit.xml for a sqlite or dedicated test connection first.
A good default is to make tests fail loudly when they detect a non-test database. A guard clause in your test setup costs ten minutes and can save a week of recovery.