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