问题
In our code we have line:
if (Configure::read('environment') != 'live') {
ConnectionManager::alias(Configure::read('environment'), 'default');
}
This means that whenever our code is not on live, our connection is going to be set as 'default' and we have this connection in app.php
I have a problem with that.
Since we are using CircleCI and our PhpUnit code fails and it gets reverted every time.
So I need to set for PhpUnit different environment variable (I need it to use 'test', not 'default').
Already tried: Scenario -
<php>
<ini name="memory_limit" value="-1"/>
<ini name="apc.enable_cli" value="1"/>
<env name="test" value="test"/>
</php>
Inside the phpunit.xml.dist
, I have set <env name='test' value='test'/>
hoping that this is going to set for phpunit different environment.
My question is how to set different environments for PhpUnit and for the rest of the code ? Or let me rephrase it, how could I use different environment variable for CircleCi and PhpUnit and our code ?
回答1:
if the Configure::read
read from the env with the getenv function, you could use the env like:
<php>
<ini name="memory_limit" value="-1"/>
<ini name="apc.enable_cli" value="1"/>
<env name="environment" value="test"/>
</php>
You could create a different configuration file like phpunit-circleci.xml and use it as argument like:
phpunit -c phpunit-circleci.xml
Hope this help
来源:https://stackoverflow.com/questions/43542229/how-to-set-a-different-phpunit-environment-variable