You are here

public function DocParserTest::testAnnotationWithVarTypeError 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::testAnnotationWithVarTypeError()
  2. 10 core/tests/Drupal/Tests/Component/Annotation/Doctrine/DocParserTest.php \Drupal\Tests\Component\Annotation\Doctrine\DocParserTest::testAnnotationWithVarTypeError()

@dataProvider getAnnotationVarTypeProviderInvalid

File

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

Class

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

Namespace

Drupal\Tests\Component\Annotation\Doctrine

Code

public function testAnnotationWithVarTypeError($attribute, $type, $value, $given) {
  $parser = $this
    ->createTestParser();
  $context = 'property SomeClassName::invalidProperty.';
  $docblock = sprintf('@Drupal\\Tests\\Component\\Annotation\\Doctrine\\Fixtures\\AnnotationWithVarType(%s = %s)', $attribute, $value);
  $parser
    ->setTarget(Target::TARGET_PROPERTY);
  try {
    $parser
      ->parse($docblock, $context);
    $this
      ->fail();
  } catch (\Doctrine\Common\Annotations\AnnotationException $exc) {
    $this
      ->assertStringContainsString("[Type Error] Attribute \"{$attribute}\" of @Drupal\\Tests\\Component\\Annotation\\Doctrine\\Fixtures\\AnnotationWithVarType declared on property SomeClassName::invalidProperty. expects a(n) {$type}, but got {$given}.", $exc
      ->getMessage());
  }
}