PHPUnit_TextUI_Command测试路径中的所有测试,而无需 --config


PHPUnit_TextUI_Command test all tests in path without --configuration

我以下列方式使用PHPUnit_TextUI_Command

$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);
你可以

只使用

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

如果您的所有案例文件都以 Test.php 结尾。

您可以使用 phpunit 选项更改后缀--test-suffix