You are here

public static function PHPUnit_Util_Test::getProvidedData in Zircon Profile 8

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

Returns the provided data for a method.

@since Method available since Release 3.2.0

Parameters

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::getProvidedData()
PHPUnit_Framework_TestSuite::createTest in vendor/phpunit/phpunit/src/Framework/TestSuite.php

File

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

Class

PHPUnit_Util_Test
Test helpers.

Code

public static function getProvidedData($className, $methodName) {
  $reflector = new ReflectionMethod($className, $methodName);
  $docComment = $reflector
    ->getDocComment();
  $data = null;
  if ($dataProviderData = self::getDataFromDataProviderAnnotation($docComment, $className, $methodName)) {
    $data = $dataProviderData;
  }
  if ($testWithData = self::getDataFromTestWithAnnotation($docComment)) {
    $data = $testWithData;
  }
  if ($data !== null) {
    if (is_object($data)) {
      $data = iterator_to_array($data);
    }
    foreach ($data as $key => $value) {
      if (!is_array($value)) {
        throw new PHPUnit_Framework_Exception(sprintf('Data set %s is invalid.', is_int($key) ? '#' . $key : '"' . $key . '"'));
      }
    }
  }
  return $data;
}