如何将自定义 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 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>
这不起作用[而且我不希望它起作用]。
-d
应该可以工作,因为 PHPget_cfg_var()功能 https://php.net/get_cfg_var读到:
$ php -d display.errors2=1 -r "echo get_cfg_var('display.errors2');"
1
传递自定义 ini 设置(或者带有以下内容的 ini 文件)-c <file>
phpunit),调用它配置:
$ php -c <file> -d setting=value $(which phpunit) <your-params>...
参考文献/另见:
-
php --help
, 命令行选项 https://www.php.net/manual/en/features.commandline.options.php, 执行 PHP 文件 https://www.php.net/manual/en/features.commandline.usage.php, get_cfg_var()功能 https://php.net/get_cfg_var
- PHPUnit 文档:命令行选项 https://phpunit.readthedocs.io/en/9.5/textui.html#command-line-options, XML 配置文件 https://phpunit.readthedocs.io/en/9.5/configuration.html
- Shell:
$( ... )
命令替换(Bash GNU 参考) https://www.gnu.org/software/bash/manual/html_node/Command-Substitution.html, which
: 为什么不用“哪个”呢?那该用什么呢? https://unix.stackexchange.com/q/85249/9340
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)