Why phpunit is not getting the correct APP_ENV as specified in phpunit.xml?
use
<env name="APP_ENV" value="testing" force="true"/><env name="CACHE_DRIVER" value="array" force="true"/><env name="SESSION_DRIVER" value="array" force="true"/><env name="QUEUE_DRIVER" value="sync" force="true"/><env name="DB_CONNECTION" value="sqlite_testing" force="true"/>
Without the force parameter, it won't work. See this issue:https://github.com/sebastianbergmann/phpunit/issues/2353and the merged PR: https://github.com/sebastianbergmann/phpunit/pull/2723
I try to answer myself with the best option I found.
If you set ENV variables at docker-compose.yml file you won't be able to overwrite them with phpunit.xml directives such as:
<env name="APP_ENV" value="testing"/>
Then you should opt for removing (like in this example) APP_ENV variable set from docker-compose.yml
And rely on .env Laravel file
APP_ENV=local
With this setup, phpunit will be able to overwrite the APP_ENV to "testing"
I'm still not 100% sure this arrangement is needed, with all docker agent versions. Another host I have with another Docker version behaves differently.