I'm using Laravel and this is my ./phpunit.xml file
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="bootstrap/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="FeatureTests">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
<testsuite name="UnitTests">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./app</directory>
</whitelist>
</filter>
<php>
<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
<env name="DB_CONNECTION" value="sqlite_testing" />
</php>
</phpunit>
我正在使用以下命令启动我的一个测试套件:
./vendor/phpunit/phpunit/phpunit --testsuite UnitTests
Inside my test method I have:
public function testAllMandatoryData()
{
dump(env('APP_ENV'));
....
}
It's displaying "local" I was expecting "testing" as specified in phpunit.xml
<env name="APP_ENV" value="testing"/>
Edit: additional details I have this laravel application running in a Docker container
在docker-compose.yml上,我设置了一些环境变量,如下所示:
environment:
- APP_ENV=local
- DB_HOST=192.168.0.22
- DB_PORT=33306
- DB_DATABASE=mydatabase
- DB_USERNAME=homestead
- DB_PASSWORD=homestead
What I've noticed is that directives in phpunit.xml like:
<env name="APP_ENV" value="testing"/>
have no effect when the name is there in the docker-compose already.
相反,如果我添加了docker compose中未定义的部分.yml将在phpunit运行时正确设置,如:
<env name="DB_CONNECTION" value="sqlite_test"/>
end Edit
What I'm missing?
Thanks