phpunit -d flag limitations?

℡╲_俬逩灬. 提交于 2019-12-12 06:15:24

问题


the manual says phpunit -d key=val allows any setting that is valid on the ini file. the exact same description of php -d

but for me it is doing absolutely nothing.

test using php alone:

$ cat test.php
<?php
var_dump( get_cfg_var('hello') );
?>

$ php -d hello=world test.php
string(5) "world"

all good! now what i get on phpunit:

$ cat test.php
<?php
class MyTest extends PHPUnit_Framework_TestCase {
        public function testA(){
                var_dump( get_cfg_var('hello') );
        }
}
?>

$ phpunit -d hello=world test.php
PHPUnit 3.7.35 by Sebastian Bergmann.

.bool(false)

how can i pass cfg_vars into phpunit via the command line?


回答1:


The -d option set the ini variable using the ini_set function, has you can see in the source code here.

So if you can change your code, you can take a value passed from the command line with the -c flag with the ini_get, as example try as follow:

    public function testA(){
            var_dump( ini_get('hello') );
    }

from the docs about get_cfg_var;

get_cfg_var() will return strictly the server php.ini

Hope this help



来源:https://stackoverflow.com/questions/32465007/phpunit-d-flag-limitations

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