2014-01-13 33 views
1

我想編寫一個腳本,用於「發現」給定文件夾中的PHPUnit測試。PHPUnit幹運行或發現測試而不執行

目前我可以執行:

phpunit . 

我所有的測試名示但它們執行這可能需要相當多的時間。

我希望能夠在沒有實際執行測試的情況下查看我在項目中進行的測試。格式類似於

ExampleTest::testNameHere 

這可能嗎?

謝謝你的時間。檢測如果一個文件包含

回答

0
/* 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; 
     } 
    } 
} 
0

代碼:

  • 繼承PHPUnit的基類,測試類(對不起,沒有在我面前的名稱)
  • 方法的類在那個以「測試」開始的課程

應該這樣做。

+1

類名是PHPUnit_Framework_TestCase –