PHPUnit_Util_Test::getDataFromTestWithAnnotation PHP Метод

getDataFromTestWithAnnotation() публичный статический Метод

public static getDataFromTestWithAnnotation ( string $docComment ) : array
$docComment string full docComment string
Результат array when @testWith annotation is defined null when @testWith annotation is omitted
    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;
        }
    }

Usage Example

Пример #1
0
 /**
  * @covers PHPUnit_Util_Test::getDataFromTestWithAnnotation
  */
 public function testTestWithThrowsProperExceptionIfDatasetCannotBeParsed()
 {
     $this->setExpectedExceptionRegExp('PHPUnit_Framework_Exception', '/^The dataset for the @testWith annotation cannot be parsed.$/');
     PHPUnit_Util_Test::getDataFromTestWithAnnotation('/**
                                                        * @testWith [s]
                                                        */');
 }
All Usage Examples Of PHPUnit_Util_Test::getDataFromTestWithAnnotation