【问题标题】:phpunit -d flag limitations?phpunit -d 标志限制?
【发布时间】:2015-09-08 18:41:16
【问题描述】:

手册上说phpunit -d key=val 允许对 ini 文件有效的任何设置。与php -d完全相同的描述

但对我来说,它完全没有做任何事情。

单独使用 php 测试:

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

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

一切都好!现在我在 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?

【问题讨论】:

  • 你已经看到this了吗?我不知道这是否适合您...

标签: php unit-testing phpunit


【解决方案1】:

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

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

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

来自docs关于get_cfg_var

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

希望有帮助

【讨论】:

  • -c 用于ini文件。 -d 注入键/值,就像在 ini 文件中一样。我有几个测试,每个取决于一个服务器设置。我想每次都在命令行上使用注入设置来运行它们。现在我正在创建一个ini文件,运行一个测试,重复。
  • 嗨 @gcb 抱歉是一个错字,正如我为 d 标志测试过的源代码的 github 链接所指的那样
猜你喜欢
  • 1970-01-01
  • 2022-08-09
  • 1970-01-01
  • 2012-05-07
  • 2014-06-04
  • 2017-03-17
  • 2011-09-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多