You are here

public static function PHPUnit_Util_Test::getDataFromTestWithAnnotation in Zircon Profile 8

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

Parameters

string $docComment full docComment string:

Return value

array when @testWith annotation is defined null when @testWith annotation is omitted

Throws

PHPUnit_Framework_Exception when @testWith annotation is defined but cannot be parsed

9 calls to PHPUnit_Util_Test::getDataFromTestWithAnnotation()
PHPUnit_Util_Test::getProvidedData in vendor/phpunit/phpunit/src/Util/Test.php
Returns the provided data for a method.
Util_TestTest::testTestWithAnnotationAfter in vendor/phpunit/phpunit/tests/Util/TestTest.php
@covers PHPUnit_Util_Test::getDataFromTestWithAnnotation
Util_TestTest::testTestWithCharacterEscape in vendor/phpunit/phpunit/tests/Util/TestTest.php
@covers PHPUnit_Util_Test::getDataFromTestWithAnnotation
Util_TestTest::testTestWithEmptyAnnotation in vendor/phpunit/phpunit/tests/Util/TestTest.php
@covers PHPUnit_Util_Test::getDataFromTestWithAnnotation
Util_TestTest::testTestWithMultiLineMultiParameterCase in vendor/phpunit/phpunit/tests/Util/TestTest.php
@covers PHPUnit_Util_Test::getDataFromTestWithAnnotation

... See full list

File

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

Class

PHPUnit_Util_Test
Test helpers.

Code

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 = array();
    foreach (explode("\n", $annotationContent) as $candidateRow) {
      $candidateRow = trim($candidateRow);
      $dataSet = json_decode($candidateRow, true);
      if (json_last_error() != JSON_ERROR_NONE) {
        break;
      }
      $data[] = $dataSet;
    }
    if (!$data) {
      throw new PHPUnit_Framework_Exception('The dataset for the @testWith annotation cannot be parsed.');
    }
    return $data;
  }
}