NekaDava's avatar

Tests refresh the main database

Hello, I have a problem using tests. When I run them, they update my main database. The configuration is as follows:

1.config/database.php

phpunit.xml

.env

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=imt0245
DB_USERNAME=****
DB_PASSWORD=****

.env.testing

DB_CONNECTION=mysql_testing
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=imt0245_test
DB_USERNAME=*****
DB_PASSWORD=*****

Execution command is

php artisan test tests/Feature/ExampleTest.php

Thank you for your answers <3

0 likes
5 replies
JussiMannisto's avatar

.env.example is an example file, it has nothing to do with the testing environment. You need to create a file called .env.testing.

tykus's avatar
tykus
Best Answer
Level 104

Did you cache your config; if you did, clear it:

php artisan config:clear

Caching config is a production optimisation, it is not intended for local development

2 likes
NekaDava's avatar

@tykus

This fixed the problem. I previously tried php artisan config:cache , but it didn't change anything.

Please or to participate in this conversation.