framework: .env is not loaded when .env.testing is
- Laravel Version: 5.4.17
- PHP Version: 7
Description:
According to the documentation
You may also create a .env.testing file. This file will override values from the .env file when running PHPUnit tests or executing Artisan commands with the --env=testing option.
However, as it seems for me, it’s not how it works. It’s loaded INSTEAD OF .env
, but it should just override the values.
Steps To Reproduce:
Copy your valid .env
file as .env.testing
. The unit testing should work as expected. Now remove the APP_KEY
from .env.testing
. Unit testing breaks now.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 16 (15 by maintainers)
You could even add some crazy extends features. :feelsgood:
Yes only 1 file is loaded, and by
override values
we mean it’ll load the values from that file not the.env
file.Sounds like a great PR. 😃
When you are creating a new
.env
file, all the configuration you need to generate should be specific to that file. Since.env.testing
is for testing only, you should always aAPP_KEY
for.env.testing
like:.env
files are present on production environments too, it’s not only for development. And you may still miss the point: if that’s the way it works, the documentation shouldn’t say it otherwise.Man the documentation is really confusing on this point.
In fact it doesn’t override values from the .env file. It doesn’t depend on the .env file at all. Am I missing something?
So how are we supposed to override values that are in
.env.testing
when running tests?I know that in
phpunit.xml
you can have testing defaults and override those with an unversioned.env.testing
file. But that only works for PHPUnit.I would rather have
.env.testing
versioned so that I could run a fresh migration of the test db just by runningAPP_ENV=testing php artisan migrate:fresh
.But then that brings about the problem that I could only have a single set of test db credentials there, and my colleagues wouldn’t have any simple way to override them if their local db is using a different username, password or db name.
Might be best for someone to simply craft a PR to make this documentation a little more clear?
It is not necessarily an error in my opinion with the framework. My opinion is that
env
files are for development purposes only.@themsaid @GrahamCampbell Your thoughts?
@m1guelpf Yes, sorry for that, I’ve fixed the description!