Summer Sale! All accounts are 50% off this week.

eggplantSword's avatar

Setting up the testing environment to use separate db

How can I setup the enviroment for testing in my proyect, right now when I run my tests my db gets all deleted.

This is what I have rn:

  • I copied my .env, pasted it as .env.testing and only changed the DB_DATABASE variable to another empty db for testing.
  • In phpunit.xml I commented out the 24-25 lines and changed them as below
<server name="DB_CONNECTION" value="mysql"/>
<server name="DB_DATABASE" value="auth_test"/>

I couldn't find much in the docs https://laravel.com/docs/8.x/testing#environment

And when I run php artisan test my db auth gets it's data deleted, what am I doing wrong so that laravel uses the other db when testing?

0 likes
3 replies
eggplantSword's avatar

@Sinnbeck I ended up changing the DB_CONNECTION in the phpunit for a custom database conection I created and that works great!.

I do have an unrelated question: Can I from the console run migrations on a specific database conection?

Please or to participate in this conversation.