2011-10-11 121 views
6

如何传递自定义php.ini给phpunit?将自定义php.ini传递给phpunit

源使用

get_cfg_var 

,而不是

ini_get 

所以很遗憾它不使用通过的ini_set,-d选项设置等值

只有这样,才能传递值现在是使用额外的php.ini。我如何将它传递给phpunit?

血淋淋的细节:

我试图通过与-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---"; 
} 

它只是呼应 “---测试---”

原因是这样使用的ini_set为好:

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

另外在phpunit.xml,我有

<php> 
    <ini name="SIEF_VALIDATOR_DOC_ROOT" value="bar"/> 
</php> 

不工作[我不指望它。

回答

5

-d应该工作,因为get_cfg_var读取那些:

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

要传递一个自定义的INI设定(或可替换地与-c <file> ini文件到PHPUnit的),调用它配置:

$ php -d setting=value `which phpunit` <your params> 

见如井:php --helphttp://www.phpunit.de/manual/3.6/en/appendixes.configuration.html

+0

我不认为phpunit将它传递给php - 请参阅我上面的编辑。 – Fakrudeen

+0

我确认,它不会从代码工作 - https://github.com/sebastianbergmann/phpunit/blob/master/PHPUnit/TextUI/Command.php – Fakrudeen

+0

@Fakrudeen:我添加了一个替代品,没有问题来调用phpunit办法。 – hakre

0

Github issue建议使用-c标志。

php -c custom-php.ini `which phpunit` ... 
相关问题