phpunit -d标志的局限性? [英] phpunit -d flag limitations?

查看:144
本文介绍了phpunit -d标志的局限性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

手册上说phpunit -d key=val允许在ini文件上有效的任何设置. php -d

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.

仅使用php进行测试:

test using php alone:

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

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

一切都很好!现在我在phpunit上得到了什么:

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)

我如何通过命令行将cfg_vars传递到phpunit中?

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

推荐答案

-d选项使用ini_set函数设置ini变量,您可以在源代码中看到

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

因此,如果您可以更改代码,则可以使用从命令行通过带有-c标志的ini_get值,例如,尝试如下操作:

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

来自文档关于get_cfg_var

from the docs about get_cfg_var;

get_cfg_var()将严格返回服务器php.ini

get_cfg_var() will return strictly the server php.ini

希望获得帮助

这篇关于phpunit -d标志的局限性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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