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