function DataProvider::dataProvidedByTestWithAnnotation
@psalm-param class-string $className
Throws
1 call to DataProvider::dataProvidedByTestWithAnnotation()
- DataProvider::providedData in vendor/
phpunit/ phpunit/ src/ Metadata/ Api/ DataProvider.php - @psalm-param class-string $className @psalm-param non-empty-string $methodName
File
-
vendor/
phpunit/ phpunit/ src/ Metadata/ Api/ DataProvider.php, line 239
Class
- DataProvider
- @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
Namespace
PHPUnit\Metadata\ApiCode
private function dataProvidedByTestWithAnnotation(string $className, string $methodName) : ?array {
$docComment = (new ReflectionMethod($className, $methodName))->getDocComment();
if ($docComment === false) {
return null;
}
$docComment = str_replace("\r\n", "\n", $docComment);
$docComment = preg_replace('/\\n\\s*\\*\\s?/', "\n", $docComment);
$docComment = substr($docComment, 0, -1);
$docComment = rtrim($docComment, "\n");
if (!preg_match('/@testWith\\s+/', $docComment, $matches, PREG_OFFSET_CAPTURE)) {
return null;
}
$offset = strlen($matches[0][0]) + (int) $matches[0][1];
$annotationContent = substr($docComment, $offset);
$data = [];
foreach (explode("\n", $annotationContent) as $candidateRow) {
$candidateRow = trim($candidateRow);
if ($candidateRow === '' || $candidateRow[0] !== '[') {
break;
}
$dataSet = json_decode($candidateRow, true);
if (json_last_error() !== JSON_ERROR_NONE) {
throw new InvalidDataProviderException('The data set for the @testWith annotation cannot be parsed: ' . json_last_error_msg());
}
$data[] = $dataSet;
}
if (!$data) {
throw new InvalidDataProviderException('The data set for the @testWith annotation cannot be parsed.');
}
return $data;
}