Solved it. Nevermind. See here: https://github.com/laravel/framework/issues/13374
I see I wasn't the only one surprised by such a behavior.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
When I run this:
php artisan config:clear
it's all great and my phpunit tests run super fast (~500ms).
But once I run this:
php artisan config:cache
then this
vendor/bin/phpunit tests/Feature/ApiCommentsTest.php
(note that this test file has trait use RefreshDatabase)
it will take ~20sec for the test to complete but most importantly it will just erase my whole database.
Glad I'm not in a production environment. This was so frightening.
Why such a behavior between the clear and cache. How do I solve this issue?
my phpunit.xml has this :
<php>
<env name="APP_ENV" value="testing"/>
<env name="DB_CONNECTION" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
<env name="MAIL_DRIVER" value="array"/>
<ini name="display_errors" value="On" />
<ini name="display_startup_errors" value="On" />
</php>
and my database.php has this:
'testing' => [
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => '',
],
So how come running a phpunit test destroyed my whole mysql database, while it's supposed to run into :memory: ?
Please note that it does indeed seem to run tests into :memory: when i execute php artisan config:clear prior to vendor/bin/phpunit tests/Feature/SomeTest.php, but thing go really bad as soon as I execute php artisan config:cache then run any test.
isn't this config command just something that is supposed to cache the env file and that's pretty much all about it?
I'm worried. Please explain.
edit: laravel 6, php7.3, debian
Solved it. Nevermind. See here: https://github.com/laravel/framework/issues/13374
I see I wasn't the only one surprised by such a behavior.
Please or to participate in this conversation.