将自定义php.ini传递给phpunit [英] passing custom php.ini to phpunit

查看:98
本文介绍了将自定义php.ini传递给phpunit的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How to pass a custom php.ini to phpunit?

来源使用

get_cfg_var 

代替

ini_get

不幸的是,它没有使用ini_set,-d选项等设置的值.

so unfortunately it doesn't use values set by ini_set, -d option etc.

现在传递值的唯一方法是使用其他php.ini.如何将其传递给phpunit?

Only way to pass the value now is to use an additional php.ini. How do I pass that into phpunit?

Gory详细信息:

我尝试用-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---";
}

它只是回显"--- test ---"

It simply echoes "---test---"

原因是这也使用了ini_set:

The reason is this uses ini_set as well:

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中

Also in the phpunit.xml, I have

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

这是行不通的(而且我不希望这样).

which doesn't work [and I don't expect it to].

推荐答案

-d应该起作用,因为get_cfg_var读取以下内容:

-d should work because get_cfg_var reads those:

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

要传递自定义ini设置(或将具有-c <file>的ini文件传递给phpunit),请对其进行配置:

To pass a custom ini setting (or alternatively the ini file with -c <file> to phpunit), invoke it configured:

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

另请参见:php --help http://www. phpunit.de/manual/3.6/en/appendixes.configuration.html

这篇关于将自定义php.ini传递给phpunit的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆