将自定义php.ini传递给phpunit

时间:2011-10-11 09:32:03

标签: php phpunit

如何将自定义php.ini传递给phpunit?

来源使用

get_cfg_var 

而不是

ini_get

很遗憾,它不使用ini_set,-d选项等设置的值。

现在只传递值的方法是使用额外的php.ini。我如何将其传递给phpunit?

血腥的细节:

我尝试使用-d

传入
phpunit --filter testgetdesc -d SIEF_VALIDATOR_DOC_ROOT="htdocs" 
--configuration tests/phpunit.xml tests/configHelperTest.php

public function testgetdesc() {
    echo get_cfg_var("SIEF_VALIDATOR_DOC_ROOT")."---test---";
}

它只是回应“---测试---”

原因是它也使用了ini_set:

https://github.com/sebastianbergmann/phpunit/blob/master/PHPUnit/TextUI/Command.php

            case 'd': {
                $ini = explode('=', $option[1]);

                if (isset($ini[0])) {
                    if (isset($ini[1])) {
                        ini_set($ini[0], $ini[1]);
                    } else {
                        ini_set($ini[0], TRUE);
                    }
                }
            }

同样在phpunit.xml中,我有

<php>
  <ini name="SIEF_VALIDATOR_DOC_ROOT" value="bar"/>
</php>

哪个不起作用[我不指望它]。

2 个答案:

答案 0 :(得分:5)

-d应该有效,因为get_cfg_var会读取这些内容:

$ php -d display.errors2=1 -r "echo get_cfg_var('display.errors2');"
1

要将自定义ini设置(或带有-c <file>的ini文件传递给phpunit),请调用它配置:

$ php -d setting=value `which phpunit` <your params>

请参阅:php --helphttp://www.phpunit.de/manual/3.6/en/appendixes.configuration.html

答案 1 :(得分:0)

Github issue建议使用-c标记。

php -c custom-php.ini `which phpunit` ...
相关问题