How to set a different Phpunit environment variable?

て烟熏妆下的殇ゞ 提交于 2021-02-10 16:14:41

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!