Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

symfony - LANG variable isn't overriden in testing environment

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?

question from:https://stackoverflow.com/questions/65840475/lang-variable-isnt-overriden-in-testing-environment

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...