/**
  * @param  string  $suiteClassName
  * @param  string  $suiteClassFile
  * @param  boolean $syntaxCheck
  * @return ReflectionClass
  * @throws RuntimeException
  * @access public
  */
 public function load($suiteClassName, $suiteClassFile = '', $syntaxCheck = TRUE)
 {
     $suiteClassName = str_replace('.php', '', $suiteClassName);
     if (empty($suiteClassFile)) {
         $suiteClassFile = str_replace('_', '/', $suiteClassName) . '.php';
     }
     if (!class_exists($suiteClassName, FALSE)) {
         if (!file_exists($suiteClassFile)) {
             $includePaths = PHPUnit_Util_Fileloader::getIncludePaths();
             foreach ($includePaths as $includePath) {
                 $file = $includePath . DIRECTORY_SEPARATOR . $suiteClassFile;
                 if (file_exists($file)) {
                     $suiteClassFile = $file;
                     break;
                 }
             }
         }
         PHPUnit_Util_Fileloader::checkAndLoad($suiteClassFile, $syntaxCheck);
     }
     if (class_exists($suiteClassName, FALSE)) {
         return new ReflectionClass($suiteClassName);
     } else {
         throw new RuntimeException(sprintf('Class %s could not be found in %s.', $suiteClassName, $suiteClassFile));
     }
 }
 /**
  * @return array
  * @access public
  */
 public function collectTests()
 {
     $includePathsIterator = new AppendIterator();
     $result = array();
     $includePaths = PHPUnit_Util_Fileloader::getIncludePaths();
     foreach ($includePaths as $includePath) {
         $includePathsIterator->append(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($includePath)));
     }
     $filterIterator = new PHPUnit_Util_FilterIterator($includePathsIterator);
     if ($this->filterIterator !== NULL) {
         $class = new ReflectionClass($this->filterIterator);
         $filterIterator = $class->newInstance($filterIterator);
     }
     foreach ($filterIterator as $file) {
         $result[] = $file;
     }
     return $result;
 }
Exemple #3
0
 /**
  * Wraps both <code>addTest()</code> and <code>addTestSuite</code>
  * as well as the separate import statements for the user's convenience.
  *
  * If the named file cannot be read or there are no new tests that can be
  * added, a <code>PHPUnit_Framework_Warning</code> will be created instead,
  * leaving the current test run untouched.
  *
  * @param  string  $filename
  * @param  boolean $syntaxCheck
  * @throws InvalidArgumentException
  * @access public
  * @since  Method available since Release 2.3.0
  * @author Stefano F. Rausch <*****@*****.**>
  */
 public function addTestFile($filename, $syntaxCheck = TRUE)
 {
     if (!is_string($filename)) {
         throw new InvalidArgumentException();
     }
     if (!file_exists($filename)) {
         $includePaths = PHPUnit_Util_Fileloader::getIncludePaths();
         foreach ($includePaths as $includePath) {
             $file = $includePath . DIRECTORY_SEPARATOR . $filename;
             if (file_exists($file)) {
                 $filename = $file;
                 break;
             }
         }
     }
     PHPUnit_Util_Class::collectStart();
     PHPUnit_Util_Fileloader::checkAndLoad($filename, $syntaxCheck);
     $newClasses = PHPUnit_Util_Class::collectEnd();
     $testsFound = FALSE;
     foreach ($newClasses as $className) {
         $class = new ReflectionClass($className);
         if (!$class->isAbstract()) {
             if ($class->hasMethod(PHPUnit_Runner_BaseTestRunner::SUITE_METHODNAME)) {
                 $method = $class->getMethod(PHPUnit_Runner_BaseTestRunner::SUITE_METHODNAME);
                 if ($method->isStatic()) {
                     $this->addTest($method->invoke(NULL));
                     $testsFound = TRUE;
                 }
             } else {
                 if ($class->implementsInterface('PHPUnit_Framework_Test')) {
                     $this->addTestSuite($class);
                     $testsFound = TRUE;
                 }
             }
         }
     }
     if (!$testsFound) {
         $this->addTest(new PHPUnit_Framework_Warning('No tests found in file "' . $filename . '".'));
     }
     $this->numTests = -1;
 }
 /**
  * @param  array  $paths
  * @param  string $suffix
  * @access public
  */
 public function __construct(array $paths = array(), $suffix = 'Test.php')
 {
     if (!empty($paths)) {
         $this->paths = $paths;
     } else {
         $this->paths = PHPUnit_Util_Fileloader::getIncludePaths();
     }
     $this->suffix = $suffix;
 }