laravel / ideas

Issues board used for Laravel internals discussions.
939 stars 28 forks source link

[Proposal] Ignore .env file when running tests #1805

Open rogervila opened 5 years ago

rogervila commented 5 years ago

Hello,

I had a test that was not working on Jenkins, and the problem was that, on my local environment, I had that variable set on my .env file.

If the .env file would not have been read while running the tests, I would have seen the error on my local environment instead of getting a false positive.

I would like PHPUnit to skip the .env file and read only the variables set on the phpunit.xml file, or the ones passed directly via command line, in order to avoid false positives/negatives.

mfn commented 5 years ago

Your Jenkins does not have .env per se. Because it's supposed to be in .gitignore because it's supposed not to be commited.

So the only way you have it there is either a) you commited it, which is a no-go or b) you created one with problematic values.

What I'm saying: by default on fresh checkout there's no .env and you have only available what you set it your phpunit.xml; unless you did something to prevent this.

rogervila commented 5 years ago

Hello @mfn Sorry, maybe I didn't explain it correctly.

The .env file is placed on my local environment and, as you say, is missing on the Jenkins workspace. This is why the test was working on my environment and was failing on Jenkins: there was a missing environment variable.

If the .env file would not have been read while running the tests, I would have seen the error on my local environment instead of getting a false positive.

mfn commented 5 years ago

👍 got your point, sorry. I think it makes sense.

rs-sliske commented 5 years ago

i wouldnt mind having a nice way of controlling where laravel gets its environment variables from (disabling .env file entirely or maybe telling it to use a different file name)

however im not sure i agree with this use case for a couple of reasons