コード例 #1
0
 /**
  * Sets array of available (implemented) unit tests
  * It will include sequencally all files from directory DIR_TESTS and collect all newly registered classes.
  * !! This approach will not work if a file has been included previously - it will not recognize its class as newly registered.
  */
 public static function getAvailableTests()
 {
     if (!is_array(self::$tests) || !count(self::$tests)) {
         $files = TestUtils::findFilesRecursive(self::$directoryTests, array('addDirs' => false, 'fileTypes' => array('php')));
         $tests = array();
         $dc_one = get_declared_classes();
         foreach ($files as $file) {
             require_once $file;
         }
         $dc_two = get_declared_classes();
         $testClasses = array_diff($dc_two, $dc_one);
         // collect class from newly included file
         foreach ($testClasses as $testClass) {
             $reflection = new ReflectionClass($testClass);
             // available from PHP5+
             $methods = $reflection->getMethods(ReflectionMethod::IS_PUBLIC);
             $file = $reflection->getFileName();
             foreach ($methods as $method) {
                 // each test method must begin with "test" prefix
                 if (preg_match('/^test/i', $method->name)) {
                     $tests[$testClass][$method->name] = array('file' => $file, 'class' => $testClass, 'method' => $method->name);
                 }
             }
         }
         ksort($tests);
         self::$tests = $tests;
     }
     return self::$tests;
 }