You are here

private static function PHPUnit_Util_Test::getDataFromDataProviderAnnotation in Zircon Profile 8.0

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

Returns the provided data for a method.

Parameters

string $docComment:

string $className:

string $methodName:

Return value

array|Iterator when a data provider is specified and exists null when no data provider is specified

Throws

PHPUnit_Framework_Exception

1 call to PHPUnit_Util_Test::getDataFromDataProviderAnnotation()
PHPUnit_Util_Test::getProvidedData in vendor/phpunit/phpunit/src/Util/Test.php
Returns the provided data for a method.

File

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

Class

PHPUnit_Util_Test
Test helpers.

Code

private static function getDataFromDataProviderAnnotation($docComment, $className, $methodName) {
  if (preg_match(self::REGEX_DATA_PROVIDER, $docComment, $matches)) {
    $dataProviderMethodNameNamespace = explode('\\', $matches[1]);
    $leaf = explode('::', array_pop($dataProviderMethodNameNamespace));
    $dataProviderMethodName = array_pop($leaf);
    if (!empty($dataProviderMethodNameNamespace)) {
      $dataProviderMethodNameNamespace = implode('\\', $dataProviderMethodNameNamespace) . '\\';
    }
    else {
      $dataProviderMethodNameNamespace = '';
    }
    if (!empty($leaf)) {
      $dataProviderClassName = $dataProviderMethodNameNamespace . array_pop($leaf);
    }
    else {
      $dataProviderClassName = $className;
    }
    $dataProviderClass = new ReflectionClass($dataProviderClassName);
    $dataProviderMethod = $dataProviderClass
      ->getMethod($dataProviderMethodName);
    if ($dataProviderMethod
      ->isStatic()) {
      $object = null;
    }
    else {
      $object = $dataProviderClass
        ->newInstance();
    }
    if ($dataProviderMethod
      ->getNumberOfParameters() == 0) {
      $data = $dataProviderMethod
        ->invoke($object);
    }
    else {
      $data = $dataProviderMethod
        ->invoke($object, $methodName);
    }
    return $data;
  }
}