2013-11-14 84 views
0

我使用PHPUnit_TextUI_Command以下方式PHPUnit_TextUI_Command測試在路徑中的所有測試,而--configuration

$path = 'a/path/to/phpunit.xml'; 

if(!file_exists($path)) 
    throw new Exception("Cannot read PHPUnit config file at '" . $path . "'"); 

$argv = array(
    '--configuration', $path, 
); 
$_SERVER['argv'] = $argv; 

PHPUnit_TextUI_Command::main(false); 

這工作得很好,但它需要phpunit.xml配置文件存在。

我真正想要做的是能夠在我的PHP代碼中設置要測試的目錄或文件,而不是在靜態phpunit.xml文件中。這樣

$argv = array(
    '--directory', "a/path/to/tests", 
); 
$_SERVER['argv'] = $argv; 

PHPUnit_TextUI_Command::main(false); 

回答

1

東西,你可以只使用

$argv = array(
    __FILE__, 
    'a/path/to/tests', 
); 
$_SERVER['argv'] = $argv; 

如果你所有的案卷與Test.php結束。

您可以用--test-suffix phpunit選項更改後綴。

相關問題