PHPUnit在不执行测试的情况下运行或发现测试

PHPUnit在不执行测试的情况下运行或发现测试,php,phpunit,Php,Phpunit,我想写一个脚本,在给定的文件夹中“发现”PHPUnit测试 目前我可以执行: phpunit . 我所有的测试名称都会显示出来,但是它们会被执行,这会花费很多时间 我想要的是能够在不实际执行测试的情况下查看项目中的测试。格式类似于 ExampleTest::testNameHere 这可能吗 谢谢你抽出时间 检测文件是否包含以下内容的代码: /* phpunit/php-file-iterator */ $iteratorFactory = new File_Iterator_Facto

我想写一个脚本,在给定的文件夹中“发现”PHPUnit测试

目前我可以执行:

phpunit . 
我所有的测试名称都会显示出来,但是它们会被执行,这会花费很多时间

我想要的是能够在不实际执行测试的情况下查看项目中的测试。格式类似于

ExampleTest::testNameHere 
这可能吗


谢谢你抽出时间

检测文件是否包含以下内容的代码:

/* phpunit/php-file-iterator */
$iteratorFactory = new File_Iterator_Factory();

$paths = array(
    /* testsuite path */
    '/var/www/project/tests/unit/phpUnit/',
);

$suffixes = array(
    'Test.php',
);
$iterator = $iteratorFactory->getFileIterator($paths, $suffixes);

foreach ($iterator as $file) {
    $fileName = $file->getFileName();
    $path = $file->getPathName();

    // you should use autoloader
    require_once $path;

    // build className, according to your file structure
    $class = preg_replace('/\.php/', '', $fileName);

    $refrlection = new ReflectionClass($class);
    $methods = $refrlection->getMethods(ReflectionMethod::IS_PUBLIC);
    foreach ($methods as $method) {

        // test* is test method
        if (preg_match('/^test[A-Z]/', $method->getName())) {
            echo $refrlection->getName() . ':' . $method->getName();
            echo PHP_EOL;
        }
    }
}
  • 为测试类继承PHPUnit基类的类(对不起,前面没有名称)
  • 类中以“test”开头的方法
应该可以做到这一点。

您正在寻找: