PHPUnit: dynamically loading different env files

Viewed 102

I'm working on a project (Laravel 6) with multiple developers.

We run PHPUnit regularly when developing, and we have the .env.testing and phpunit.xml files committed to the repo so that all developers have the same testing environment defined.

We are now looking at how we could run PHPUnit on our development server as a final check. However, because the .env.testing and phpunit.xml files are geared to run on our local machines, how can I tell PHPUnit on the development server to use a separate .env file?

1 Answers

I don't really see the point of committing .env.testing, since it in my opinion defeats the purpose of .env files (setting different environment variables depending on your server / OS etc.).

At the moment you are locking your developers / server into using this specific .env file, so what I would recommend doing instead is the following:

I would remove .env.testing from your repo, add a new .env.testing.example that has all the default values that you need to run it locally, this allows every developer to copy the file to .env.testing while still allowing specfic enviroment values to be set by each developer, this will also allow you to have a custom .env.testing file for your development server.

Related