You are here

public function DocParserTest::testAnnotationWithRequiredAttributesWithoutContructor in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Component/Annotation/Doctrine/DocParserTest.php \Drupal\Tests\Component\Annotation\Doctrine\DocParserTest::testAnnotationWithRequiredAttributesWithoutContructor()
  2. 10 core/tests/Drupal/Tests/Component/Annotation/Doctrine/DocParserTest.php \Drupal\Tests\Component\Annotation\Doctrine\DocParserTest::testAnnotationWithRequiredAttributesWithoutContructor()

File

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

Class

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

Namespace

Drupal\Tests\Component\Annotation\Doctrine

Code

public function testAnnotationWithRequiredAttributesWithoutContructor() {
  $parser = $this
    ->createTestParser();
  $context = 'property SomeClassName::invalidProperty.';
  $parser
    ->setTarget(Target::TARGET_PROPERTY);
  $docblock = '@Drupal\\Tests\\Component\\Annotation\\Doctrine\\Fixtures\\AnnotationWithRequiredAttributesWithoutContructor("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\\AnnotationWithRequiredAttributesWithoutContructor', $result[0]);
  $this
    ->assertEquals("Some Value", $result[0]->value);
  $this
    ->assertInstanceOf('Drupal\\Tests\\Component\\Annotation\\Doctrine\\Fixtures\\AnnotationTargetAnnotation', $result[0]->annot);
  $docblock = '@Drupal\\Tests\\Component\\Annotation\\Doctrine\\Fixtures\\AnnotationWithRequiredAttributesWithoutContructor("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\\AnnotationWithRequiredAttributesWithoutContructor 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\\AnnotationWithRequiredAttributesWithoutContructor(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\\AnnotationWithRequiredAttributesWithoutContructor declared on property SomeClassName::invalidProperty. expects a(n) string. This value should not be null.', $exc
      ->getMessage());
  }
}