如何将自定义php.ini传递给phpunit?
来源使用
get_cfg_var
Run Code Online (Sandbox Code Playgroud)
代替
ini_get
Run Code Online (Sandbox Code Playgroud)
所以不幸的是它不使用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---";
}
Run Code Online (Sandbox Code Playgroud)
它简单地回应"---测试---"
原因是它也使用了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);
}
}
}
Run Code Online (Sandbox Code Playgroud)
同样在phpunit.xml中,我有
<php>
<ini name="SIEF_VALIDATOR_DOC_ROOT" value="bar"/>
</php>
Run Code Online (Sandbox Code Playgroud)
哪个不起作用[我不指望它].
-d应该工作,因为get_cfg_var读取:
$ php -d display.errors2=1 -r "echo get_cfg_var('display.errors2');"
1
Run Code Online (Sandbox Code Playgroud)
要传递自定义ini设置(或者将ini文件与-c <file>phpunit 一起传递),请调用它配置:
$ php -d setting=value `which phpunit` <your params>
Run Code Online (Sandbox Code Playgroud)
见还有:php --help,http://www.phpunit.de/manual/3.6/en/appendixes.configuration.html