0

I'm working on a Symfony 4.4 project. The project has been created from scratch (it's not an update from a 3.4 codebase or something like that). I'm adding automated tests to my codebase, but I'm having problems with environment variables.

In my .env, .env.local, .env.test and .env.test.local I have defined a LANG variable, to set the application language. To correctly test translations when I'm developing, in the dev environment (.env.local file) I've set LANG=es, and it's working correctly. In production it's also working correctly, but in test, in the .env.test.local file I've set LANG=ca but neither PHPUnit nor bin/console debug:container --env-vars --env=test show the correct value for this variable, it's value it's just es_ES.UTF-8, the value of the $LANG variable in my Ubuntu system.

I have other environment variables defined in the .env.test.local file, and these are correctly (like the DATABASE_URL). I've also tried to add the LANG in the phpunit.xml.dist file (<env name="LANG" value="ca" />), but it the value doesn't change, it's still es_ES.UTF-8.

I've also deleted the var/cache/test directory, but it still doesn't work.

What I'm doing wrong? What can I do to change the language in the testing environment?

mHouses
  • 875
  • 1
  • 16
  • 36
  • 1
    Could you test run your tests by passing $LANG=ca, for example `$LANG=ca ./bin/phpunit`? I have to confirm it but env variables of your system are the main used (top priority) – qdequippe Jan 22 '21 at 09:58
  • @qdequippe you are right: I've opened a new terminal, run `export LANG=ca` and then `bin/phpunit`, and the content of the site was in the correct language. Also, running `bin/console debug:container --env-vars --env=test` shows the correct language... Also, if I show the vars of the dev environment, the language is also `ca` (the one in the system) instead of `es`, the one in the `.env.local` file. But why? – mHouses Jan 22 '21 at 10:16

1 Answers1

1

Check https://symfony.com/doc/current/configuration.html#overriding-environment-values-via-env-local

Real environment variables always win over env vars created by any of the .env files.

qdequippe
  • 1,075
  • 6
  • 15