phpunit -d标志的局限性? [英] phpunit -d flag limitations?
问题描述
手册上说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屋!