You are here

private static function PHPUnit_Util_Test::resolveElementToReflectionObjects in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/phpunit/phpunit/src/Util/Test.php \PHPUnit_Util_Test::resolveElementToReflectionObjects()

@since Method available since Release 4.0.0

Parameters

string $element:

Return value

array

Throws

PHPUnit_Framework_InvalidCoversTargetException

1 call to PHPUnit_Util_Test::resolveElementToReflectionObjects()
PHPUnit_Util_Test::getLinesToBeCoveredOrUsed in vendor/phpunit/phpunit/src/Util/Test.php
@since Method available since Release 4.2.0

File

vendor/phpunit/phpunit/src/Util/Test.php, line 847

Class

PHPUnit_Util_Test
Test helpers.

Code

private static function resolveElementToReflectionObjects($element) {
  $codeToCoverList = array();
  if (strpos($element, '\\') !== false && function_exists($element)) {
    $codeToCoverList[] = new ReflectionFunction($element);
  }
  else {
    if (strpos($element, '::') !== false) {
      list($className, $methodName) = explode('::', $element);
      if (isset($methodName[0]) && $methodName[0] == '<') {
        $classes = array(
          $className,
        );
        foreach ($classes as $className) {
          if (!class_exists($className) && !interface_exists($className)) {
            throw new PHPUnit_Framework_InvalidCoversTargetException(sprintf('Trying to @cover or @use not existing class or ' . 'interface "%s".', $className));
          }
          $class = new ReflectionClass($className);
          $methods = $class
            ->getMethods();
          $inverse = isset($methodName[1]) && $methodName[1] == '!';
          if (strpos($methodName, 'protected')) {
            $visibility = 'isProtected';
          }
          elseif (strpos($methodName, 'private')) {
            $visibility = 'isPrivate';
          }
          elseif (strpos($methodName, 'public')) {
            $visibility = 'isPublic';
          }
          foreach ($methods as $method) {
            if ($inverse && !$method
              ->{$visibility}()) {
              $codeToCoverList[] = $method;
            }
            elseif (!$inverse && $method
              ->{$visibility}()) {
              $codeToCoverList[] = $method;
            }
          }
        }
      }
      else {
        $classes = array(
          $className,
        );
        foreach ($classes as $className) {
          if ($className == '' && function_exists($methodName)) {
            $codeToCoverList[] = new ReflectionFunction($methodName);
          }
          else {
            if (!((class_exists($className) || interface_exists($className) || trait_exists($className)) && method_exists($className, $methodName))) {
              throw new PHPUnit_Framework_InvalidCoversTargetException(sprintf('Trying to @cover or @use not existing method "%s::%s".', $className, $methodName));
            }
            $codeToCoverList[] = new ReflectionMethod($className, $methodName);
          }
        }
      }
    }
    else {
      $extended = false;
      if (strpos($element, '<extended>') !== false) {
        $element = str_replace('<extended>', '', $element);
        $extended = true;
      }
      $classes = array(
        $element,
      );
      if ($extended) {
        $classes = array_merge($classes, class_implements($element), class_parents($element));
      }
      foreach ($classes as $className) {
        if (!class_exists($className) && !interface_exists($className) && !trait_exists($className)) {
          throw new PHPUnit_Framework_InvalidCoversTargetException(sprintf('Trying to @cover or @use not existing class or ' . 'interface "%s".', $className));
        }
        $codeToCoverList[] = new ReflectionClass($className);
      }
    }
  }
  return $codeToCoverList;
}