Ejemplo n.º 1
0
 /**
  * @covers Brickoo\Component\Annotation\AnnotationParser::parse
  * @covers Brickoo\Component\Annotation\AnnotationParser::getAnnotationsMatches
  * @covers Brickoo\Component\Annotation\AnnotationParser::getAnnotationList
  * @covers Brickoo\Component\Annotation\AnnotationParser::isAnnotationInWhitelist
  * @covers Brickoo\Component\Annotation\AnnotationParser::getAnnotationValues
  * @covers Brickoo\Component\Annotation\AnnotationParser::getParameterValues
  * @covers Brickoo\Component\Annotation\AnnotationParser::attachParameterValues
  * @covers Brickoo\Component\Annotation\AnnotationParser::convertValue
  * @covers Brickoo\Component\Annotation\AnnotationParser::transformScalar
  * @covers Brickoo\Component\Annotation\AnnotationParser::transformIfIsNumeric
  * @covers Brickoo\Component\Annotation\AnnotationParser::transformIfIsBoolean
  * @covers Brickoo\Component\Annotation\AnnotationParser::convertAnnotations
  */
 public function testParseAnnotatedDocComment()
 {
     $docComment = '/**
         * @:Assert ("[[\'a\', \'b\', key=\'c\']]" false true)
         * Some comment about the implementation.
         * @:Cache (path = "/temp" lifetime = 30)
         * @param string $someValue
         * @return void
         */';
     $target = Annotation::TARGET_CLASS;
     $targetLocation = "";
     $annotationParser = new AnnotationParser();
     $annotationParser->setAnnotationPrefix("@:");
     $annotationParser->setAnnotationWhitelist(["Cache", "Assert"]);
     $annotations = $annotationParser->parse($target, $targetLocation, $docComment);
     $this->assertInternalType("array", $annotations);
     $this->assertEquals(2, count($annotations));
     $annotation_1 = array_pop($annotations);
     $this->assertEquals($target, $annotation_1->getTarget());
     $this->assertEquals($targetLocation, $annotation_1->getTargetLocation());
     $this->assertEquals("Cache", $annotation_1->getName());
     $this->assertEquals(["path" => "/temp", "lifetime" => 30], $annotation_1->getValues());
     $annotation_2 = array_pop($annotations);
     $this->assertEquals($target, $annotation_1->getTarget());
     $this->assertEquals($targetLocation, $annotation_1->getTargetLocation());
     $this->assertEquals("Assert", $annotation_2->getName());
     $this->assertEquals([0 => ['a', 'b', 'key' => 'c'], 1 => false, 2 => true], $annotation_2->getValues());
 }
 /**
  * Parse the doc comments annotations.
  * @param AnnotationReaderResult $result
  * @param integer $target
  * @param string $targetLocation
  * @param string $docComment
  * @return \Brickoo\Component\Annotation\AnnotationReflectionClassReader
  */
 private function parseAnnotations(AnnotationReaderResult $result, $target, $targetLocation, $docComment)
 {
     if ($annotations = $this->annotationParser->parse($target, $targetLocation, $docComment)) {
         $this->addResultAnnotations($result, $annotations);
     }
     return $this;
 }