You are here

public function DocParserTest::testAnnotationWithoutConstructor in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Component/Annotation/Doctrine/DocParserTest.php \Drupal\Tests\Component\Annotation\Doctrine\DocParserTest::testAnnotationWithoutConstructor()

File

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

Class

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

Namespace

Drupal\Tests\Component\Annotation\Doctrine

Code

public function testAnnotationWithoutConstructor() {
  $parser = $this
    ->createTestParser();
  $docblock = <<<DOCBLOCK
/**
 * @SomeAnnotationClassNameWithoutConstructor("Some data")
 */
DOCBLOCK;
  $result = $parser
    ->parse($docblock);
  $this
    ->assertCount(1, $result);
  $annot = $result[0];
  $this
    ->assertNotNull($annot);
  $this
    ->assertInstanceOf(SomeAnnotationClassNameWithoutConstructor::class, $annot);
  $this
    ->assertNull($annot->name);
  $this
    ->assertNotNull($annot->data);
  $this
    ->assertEquals($annot->data, "Some data");
  $docblock = <<<DOCBLOCK
/**
 * @SomeAnnotationClassNameWithoutConstructor(name="Some Name", data = "Some data")
 */
DOCBLOCK;
  $result = $parser
    ->parse($docblock);
  $this
    ->assertCount(1, $result);
  $annot = $result[0];
  $this
    ->assertNotNull($annot);
  $this
    ->assertInstanceOf(SomeAnnotationClassNameWithoutConstructor::class, $annot);
  $this
    ->assertEquals($annot->name, "Some Name");
  $this
    ->assertEquals($annot->data, "Some data");
  $docblock = <<<DOCBLOCK
/**
 * @SomeAnnotationClassNameWithoutConstructor(data = "Some data")
 */
DOCBLOCK;
  $result = $parser
    ->parse($docblock);
  $this
    ->assertCount(1, $result);
  $annot = $result[0];
  $this
    ->assertEquals($annot->data, "Some data");
  $this
    ->assertNull($annot->name);
  $docblock = <<<DOCBLOCK
/**
 * @SomeAnnotationClassNameWithoutConstructor(name = "Some name")
 */
DOCBLOCK;
  $result = $parser
    ->parse($docblock);
  $this
    ->assertCount(1, $result);
  $annot = $result[0];
  $this
    ->assertEquals($annot->name, "Some name");
  $this
    ->assertNull($annot->data);
  $docblock = <<<DOCBLOCK
/**
 * @SomeAnnotationClassNameWithoutConstructor("Some data")
 */
DOCBLOCK;
  $result = $parser
    ->parse($docblock);
  $this
    ->assertCount(1, $result);
  $annot = $result[0];
  $this
    ->assertEquals($annot->data, "Some data");
  $this
    ->assertNull($annot->name);
  $docblock = <<<DOCBLOCK
/**
 * @SomeAnnotationClassNameWithoutConstructor("Some data",name = "Some name")
 */
DOCBLOCK;
  $result = $parser
    ->parse($docblock);
  $this
    ->assertCount(1, $result);
  $annot = $result[0];
  $this
    ->assertEquals($annot->name, "Some name");
  $this
    ->assertEquals($annot->data, "Some data");
  $docblock = <<<DOCBLOCK
/**
 * @SomeAnnotationWithConstructorWithoutParams(name = "Some name")
 */
DOCBLOCK;
  $result = $parser
    ->parse($docblock);
  $this
    ->assertCount(1, $result);
  $annot = $result[0];
  $this
    ->assertEquals($annot->name, "Some name");
  $this
    ->assertEquals($annot->data, "Some data");
  $docblock = <<<DOCBLOCK
/**
 * @SomeAnnotationClassNameWithoutConstructorAndProperties()
 */
DOCBLOCK;
  $result = $parser
    ->parse($docblock);
  $this
    ->assertCount(1, $result);
  $this
    ->assertInstanceOf(SomeAnnotationClassNameWithoutConstructorAndProperties::class, $result[0]);
}