pestphp / pest

Pest is an elegant PHP testing Framework with a focus on simplicity, meticulously designed to bring back the joy of testing in PHP.
https://pestphp.com
MIT License
9.12k stars 319 forks source link

[Bug]: Pest complains about missing .env file when run within a docker container #1028

Open PatrickMessierGoC opened 7 months ago

PatrickMessierGoC commented 7 months ago

What Happened

When running Pest tests inside a docker container that does NOT contain either a .env.testing or a .env file, we systematically get the following warning when the first 2 tests are executed : → file_get_contents(/usr/share/nginx/lp-opn/.env): Failed to open stream: No such file or directory.

image

Environment variables are injected inside the container using docker compose env_file option.

image

Surprisingly, the rest of the test are running just fine.

We don't have this behaviour when running equivalent tests with phpunit.

How to Reproduce

Starting with an existing Laravel app with a Pest Test suite:

  1. Create a .dockerignore file and add .env and .env.testing to it.
  2. Build a docker container with the application code
  3. Start the application container.
  4. Execute the Laravel Pest Suite from within the docker container.

Sample Repository

https://dev.azure.com/CSPS-EFPC-UX/learning-platform/_git/lp-opn

Pest Version

2.24.0

PHP Version

8.1.26

Operation System

Linux

Notes

No response

fabio-ivona commented 7 months ago

Have you tried to load the env file in the volume?

PatrickMessierGoC commented 7 months ago

@fabio-ivona No. In fact, the question here is not about getting the env files in the container but rather about why Pest behaves this way when the environment variables are "injected" in the container rather than defined via an .env.testing file that sounds like optional based on Laravel Docs. We know the environment variables are somehow available in the container because all remaining tests runs successfully.