Returns the provided data for a method.
@since Method available since Release 3.2.0
string $className:
string $methodName:
string $docComment:
mixed array|Iterator when a data provider is specified and exists false when a data provider is specified and does not exist null when no data provider is specified
public static function getProvidedData($className, $methodName) {
$reflector = new ReflectionMethod($className, $methodName);
$docComment = $reflector
->getDocComment();
$data = NULL;
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 = join('\\', $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);
}
}
if ($data !== NULL) {
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;
}