1
我想編寫一個腳本,用於「發現」給定文件夾中的PHPUnit測試。PHPUnit幹運行或發現測試而不執行
目前我可以執行:
phpunit .
我所有的測試名示但它們執行這可能需要相當多的時間。
我希望能夠在沒有實際執行測試的情況下查看我在項目中進行的測試。格式類似於
ExampleTest::testNameHere
這可能嗎?
謝謝你的時間。檢測如果一個文件包含
我想編寫一個腳本,用於「發現」給定文件夾中的PHPUnit測試。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_Framework_TestCase –