diff --git a/src/Util/Test.php b/src/Util/Test.php index cef33b37819..617ef4c0cc5 100644 --- a/src/Util/Test.php +++ b/src/Util/Test.php @@ -469,9 +469,15 @@ public static function getDataFromTestWithAnnotation($docComment) $data = array(); 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) { - break; + $error = function_exists('json_last_error_msg') ? json_last_error_msg() : json_last_error(); + throw new PHPUnit_Framework_Exception( + 'The dataset for the @testWith annotation cannot be parsed: '.$error + ); } $data[] = $dataSet; } diff --git a/tests/Util/TestTest.php b/tests/Util/TestTest.php index 2ec3829b15b..2b425364a12 100644 --- a/tests/Util/TestTest.php +++ b/tests/Util/TestTest.php @@ -346,13 +346,25 @@ public function testTestWithThrowsProperExceptionIfDatasetCannotBeParsed() { $this->setExpectedExceptionRegExp( 'PHPUnit_Framework_Exception', - '/^The dataset for the @testWith annotation cannot be parsed.$/' + '/^The dataset for the @testWith annotation cannot be parsed:/' ); PHPUnit_Util_Test::getDataFromTestWithAnnotation('/** * @testWith [s] */'); } + public function testTestWithThrowsProperExceptionIfMultiLineDatasetCannotBeParsed() + { + $this->setExpectedExceptionRegExp( + 'PHPUnit_Framework_Exception', + '/^The dataset for the @testWith annotation cannot be parsed:/' + ); + PHPUnit_Util_Test::getDataFromTestWithAnnotation('/** + * @testWith ["valid"] + * [invalid] + */'); + } + /** * @covers PHPUnit_Util_Test::getDependencies *