2015-09-08 41 views
0

手冊中說phpunit -d key=val允許任何在ini文件中有效的設置。完全相同的描述php -dphpunit -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) 

我怎麼能通過cfunit通過命令行phpunit?

+0

你們已經看到[這](https://github.com/sebastianbergmann/phpunit/issues/940)?我不知道這是否可以成爲您的解決方法... – Matteo

回答

1

-d選項使用ini_set函數設置ini變量,您可以在源代碼here中看到。

所以,如果你可以改變你的代碼,你可以從與該ini_get -c標誌在命令行中傳遞的值,如例嘗試如下:從docsget_cfg_var

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

;

get_cfg_var()將嚴格返回服務器的php.ini

希望這有助於

+0

'-c'是一個ini文件。 '-d'可以像插入ini文件一樣注入鍵/值。我有幾個測試,每個都取決於一個服務器設置。我想每次都在命令行中使用注入設置來運行它們。現在我創建一個ini文件,運行一個測試,重複。 – gcb

+0

hi @gcb抱歉,是一個錯字,因爲提到的github鏈接到我測試d標誌的源代碼 – Matteo