pest icon indicating copy to clipboard operation
pest copied to clipboard

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

Open PatrickMessierGoC opened this issue 1 year ago • 2 comments

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

PatrickMessierGoC avatar Dec 06 '23 19:12 PatrickMessierGoC

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

fabio-ivona avatar Dec 06 '23 21:12 fabio-ivona

@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.

PatrickMessierGoC avatar Dec 06 '23 21:12 PatrickMessierGoC