Why are your .env.testing keys starting DB_TEST_ and not just DB_ (like they would be in .env)?
DB_CONNECTION=testing
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=test
DB_USERNAME=root
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I'm trying to use a seperate MySQL database for testing but it appears to just be ignoring any of the setup I've done as it keeps going to my local database and wiping everything in there.
So how do I do this? I've got a .env.testing file setup with the following:
APP_NAME="Laravel Test"
APP_ENV=testing
APP_KEY=base64:iSgW1vFSRF9ieXJpLps9+IvET2U8vcG7iw0NLE2yRvM=
APP_DEBUG=true
APP_URL=http://localhost
DB_TEST_CONNECTION=testing
DB_TEST_HOST=127.0.0.1
DB_TEST_PORT=3306
DB_TEST_DATABASE=test
DB_TEST_USERNAME=root
PHP Unit has the following:
<php>
<env name="APP_ENV" value="testing"/>
<env name="BCRYPT_ROUNDS" value="4"/>
<env name="CACHE_DRIVER" value="array"/>
<!-- <env name="DB_CONNECTION" value="testing"/> -->
<!-- <env name="DB_DATABASE" value=":memory:"/> -->
<env name="MAIL_MAILER" value="array"/>
<env name="QUEUE_CONNECTION" value="sync"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="TELESCOPE_ENABLED" value="false"/>
</php>
If I uncomment the DB_CONNECTION line, then it does attempt to use the testing connection I have the database config file, but it attempts to connect with the default forge credentials, apparently completely overlooking the .env.testing file.
Ater making any changes I also do php artisan config:cache --env=testing
I've searched and searched on this and as far as I can tell I'm doing everything right, but I must be missing something.
Please or to participate in this conversation.