You are here

class PHPUnit_Runner_StandardTestSuiteLoader in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/phpunit/phpunit/src/Runner/StandardTestSuiteLoader.php \PHPUnit_Runner_StandardTestSuiteLoader

The standard test suite loader.

@since Class available since Release 2.0.0

Hierarchy

Expanded class hierarchy of PHPUnit_Runner_StandardTestSuiteLoader

2 string references to 'PHPUnit_Runner_StandardTestSuiteLoader'
PHPUnit_TextUI_Command::handleLoader in vendor/phpunit/phpunit/src/TextUI/Command.php
Handles the loading of the PHPUnit_Runner_TestSuiteLoader implementation.
Util_ConfigurationTest::testPHPUnitConfigurationIsReadCorrectly in vendor/phpunit/phpunit/tests/Util/ConfigurationTest.php
@covers PHPUnit_Util_Configuration::getPHPUnitConfiguration

File

vendor/phpunit/phpunit/src/Runner/StandardTestSuiteLoader.php, line 16

View source
class PHPUnit_Runner_StandardTestSuiteLoader implements PHPUnit_Runner_TestSuiteLoader {

  /**
   * @param  string                      $suiteClassName
   * @param  string                      $suiteClassFile
   * @return ReflectionClass
   * @throws PHPUnit_Framework_Exception
   */
  public function load($suiteClassName, $suiteClassFile = '') {
    $suiteClassName = str_replace('.php', '', $suiteClassName);
    if (empty($suiteClassFile)) {
      $suiteClassFile = PHPUnit_Util_Filesystem::classNameToFilename($suiteClassName);
    }
    if (!class_exists($suiteClassName, false)) {
      $loadedClasses = get_declared_classes();
      $filename = PHPUnit_Util_Fileloader::checkAndLoad($suiteClassFile);
      $loadedClasses = array_values(array_diff(get_declared_classes(), $loadedClasses));
    }
    if (!class_exists($suiteClassName, false) && !empty($loadedClasses)) {
      $offset = 0 - strlen($suiteClassName);
      foreach ($loadedClasses as $loadedClass) {
        $class = new ReflectionClass($loadedClass);
        if (substr($loadedClass, $offset) === $suiteClassName && $class
          ->getFileName() == $filename) {
          $suiteClassName = $loadedClass;
          break;
        }
      }
    }
    if (!class_exists($suiteClassName, false) && !empty($loadedClasses)) {
      $testCaseClass = 'PHPUnit_Framework_TestCase';
      foreach ($loadedClasses as $loadedClass) {
        $class = new ReflectionClass($loadedClass);
        $classFile = $class
          ->getFileName();
        if ($class
          ->isSubclassOf($testCaseClass) && !$class
          ->isAbstract()) {
          $suiteClassName = $loadedClass;
          $testCaseClass = $loadedClass;
          if ($classFile == realpath($suiteClassFile)) {
            break;
          }
        }
        if ($class
          ->hasMethod('suite')) {
          $method = $class
            ->getMethod('suite');
          if (!$method
            ->isAbstract() && $method
            ->isPublic() && $method
            ->isStatic()) {
            $suiteClassName = $loadedClass;
            if ($classFile == realpath($suiteClassFile)) {
              break;
            }
          }
        }
      }
    }
    if (class_exists($suiteClassName, false)) {
      $class = new ReflectionClass($suiteClassName);
      if ($class
        ->getFileName() == realpath($suiteClassFile)) {
        return $class;
      }
    }
    throw new PHPUnit_Framework_Exception(sprintf("Class '%s' could not be found in '%s'.", $suiteClassName, $suiteClassFile));
  }

  /**
   * @param  ReflectionClass $aClass
   * @return ReflectionClass
   */
  public function reload(ReflectionClass $aClass) {
    return $aClass;
  }

}

Members