Tests keep getting run on my dev db rather than test db
I don't know what's changed, but for some reason sometimes when I run"php artisan test" on my local machine, rather than doing what it used to do (Run against the test database), it runs against my development database. I also get the following error:
I'm guessing you don't use the correct parameter when running the tests.
The .env.testing Environment File
In addition, you may create a .env.testing file in the root of your project. This file will be used instead of the .env file when running PHPUnit tests or executing Artisan commands with the --env=testing option.
@Tray2 Do I have to use --env=testing every time to use the .env.testing? Because I already had a .env.testing, and I never had to use --env=testing a few weeks ago.
@jaracas According to the docs yes, or you can make an alias for it, or delete your test env file and update your phpunit.xml instead to use the proper database.
@jaracas If you have the right db credentials in your .env.testing file you don't need to specify those in the phpunit config. You can remove these from the config.
@jaracas Yes. If you cache your configuration then Laravel’s going to stop reading environment variables and just read from the cached config instead, which will contain your site’s database credentials.
Run php artisan config:clear and avoid running in locally in the future. You should only be caching things like configuration as part of your deployment process to your production server.