function DocParserTest::testAnnotationWithRequiredAttributes

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Component/Annotation/Doctrine/DocParserTest.php \Drupal\Tests\Component\Annotation\Doctrine\DocParserTest::testAnnotationWithRequiredAttributes()
  2. 8.9.x core/tests/Drupal/Tests/Component/Annotation/Doctrine/DocParserTest.php \Drupal\Tests\Component\Annotation\Doctrine\DocParserTest::testAnnotationWithRequiredAttributes()
  3. 11.x core/tests/Drupal/Tests/Component/Annotation/Doctrine/DocParserTest.php \Drupal\Tests\Component\Annotation\Doctrine\DocParserTest::testAnnotationWithRequiredAttributes()

File

core/tests/Drupal/Tests/Component/Annotation/Doctrine/DocParserTest.php, line 643

Class

DocParserTest
@coversDefaultClass \Drupal\Component\Annotation\Doctrine\DocParser

Namespace

Drupal\Tests\Component\Annotation\Doctrine

Code

public function testAnnotationWithRequiredAttributes() {
    $parser = $this->createTestParser();
    $context = 'property SomeClassName::invalidProperty.';
    $parser->setTarget(Target::TARGET_PROPERTY);
    $docblock = '@Drupal\\Tests\\Component\\Annotation\\Doctrine\\Fixtures\\AnnotationWithRequiredAttributes("Some Value", annot = @Drupal\\Tests\\Component\\Annotation\\Doctrine\\Fixtures\\AnnotationTargetAnnotation)';
    $result = $parser->parse($docblock);
    $this->assertCount(1, $result);
    $this->assertInstanceOf('Drupal\\Tests\\Component\\Annotation\\Doctrine\\Fixtures\\AnnotationWithRequiredAttributes', $result[0]);
    $this->assertEquals("Some Value", $result[0]->getValue());
    $this->assertInstanceOf('Drupal\\Tests\\Component\\Annotation\\Doctrine\\Fixtures\\AnnotationTargetAnnotation', $result[0]->getAnnot());
    $docblock = '@Drupal\\Tests\\Component\\Annotation\\Doctrine\\Fixtures\\AnnotationWithRequiredAttributes("Some Value")';
    try {
        $result = $parser->parse($docblock, $context);
        $this->fail();
    } catch (\Doctrine\Common\Annotations\AnnotationException $exc) {
        $this->assertStringContainsString('Attribute "annot" of @Drupal\\Tests\\Component\\Annotation\\Doctrine\\Fixtures\\AnnotationWithRequiredAttributes declared on property SomeClassName::invalidProperty. expects a(n) Drupal\\Tests\\Component\\Annotation\\Doctrine\\Fixtures\\AnnotationTargetAnnotation. This value should not be null.', $exc->getMessage());
    }
    $docblock = '@Drupal\\Tests\\Component\\Annotation\\Doctrine\\Fixtures\\AnnotationWithRequiredAttributes(annot = @Drupal\\Tests\\Component\\Annotation\\Doctrine\\Fixtures\\AnnotationTargetAnnotation)';
    try {
        $result = $parser->parse($docblock, $context);
        $this->fail();
    } catch (\Doctrine\Common\Annotations\AnnotationException $exc) {
        $this->assertStringContainsString('Attribute "value" of @Drupal\\Tests\\Component\\Annotation\\Doctrine\\Fixtures\\AnnotationWithRequiredAttributes declared on property SomeClassName::invalidProperty. expects a(n) string. This value should not be null.', $exc->getMessage());
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.