passing custom php.ini to phpunit

与世无争的帅哥 提交于 2020-01-03 10:58:14

问题


How to pass a custom php.ini to phpunit?

The source uses

get_cfg_var 

instead of

ini_get

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

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

Gory details:

I tried passing in with -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---";
}

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

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);
                    }
                }
            }

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].


回答1:


-d should work because get_cfg_var reads those:

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

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>

See as well: php --help, http://www.phpunit.de/manual/3.6/en/appendixes.configuration.html




回答2:


The Github issue recommends using the -c flag.

php -c custom-php.ini `which phpunit` ...


来源:https://stackoverflow.com/questions/7723959/passing-custom-php-ini-to-phpunit

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