public static function getDataFromTestWithAnnotation($docComment)
{
$docComment = self::cleanUpMultiLineAnnotation($docComment);
if (preg_match(self::REGEX_TEST_WITH, $docComment, $matches, PREG_OFFSET_CAPTURE)) {
$offset = strlen($matches[0][0]) + $matches[0][1];
$annotationContent = substr($docComment, $offset);
$data = [];
foreach (explode("\n", $annotationContent) as $candidateRow) {
$candidateRow = trim($candidateRow);
if ($candidateRow[0] !== '[') {
break;
}
$dataSet = json_decode($candidateRow, true);
if (json_last_error() != JSON_ERROR_NONE) {
throw new PHPUnit_Framework_Exception('The dataset for the @testWith annotation cannot be parsed: ' . json_last_error_msg());
}
$data[] = $dataSet;
}
if (!$data) {
throw new PHPUnit_Framework_Exception('The dataset for the @testWith annotation cannot be parsed.');
}
return $data;
}
}