function DocParserTest::testAnnotationWithoutConstructor

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Component/Annotation/Doctrine/DocParserTest.php \Drupal\Tests\Component\Annotation\Doctrine\DocParserTest::testAnnotationWithoutConstructor()
  2. 8.9.x core/tests/Drupal/Tests/Component/Annotation/Doctrine/DocParserTest.php \Drupal\Tests\Component\Annotation\Doctrine\DocParserTest::testAnnotationWithoutConstructor()
  3. 11.x 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 196

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("Some data", $annot->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("Some Name", $annot->name);
    $this->assertEquals("Some data", $annot->data);
    $docblock = <<<DOCBLOCK
/**
 * @SomeAnnotationClassNameWithoutConstructor(data = "Some data")
 */
DOCBLOCK;
    $result = $parser->parse($docblock);
    $this->assertCount(1, $result);
    $annot = $result[0];
    $this->assertEquals("Some data", $annot->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("Some name", $annot->name);
    $this->assertNull($annot->data);
    $docblock = <<<DOCBLOCK
/**
 * @SomeAnnotationClassNameWithoutConstructor("Some data")
 */
DOCBLOCK;
    $result = $parser->parse($docblock);
    $this->assertCount(1, $result);
    $annot = $result[0];
    $this->assertEquals("Some data", $annot->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("Some name", $annot->name);
    $this->assertEquals("Some data", $annot->data);
    $docblock = <<<DOCBLOCK
/**
 * @SomeAnnotationWithConstructorWithoutParams(name = "Some name")
 */
DOCBLOCK;
    $result = $parser->parse($docblock);
    $this->assertCount(1, $result);
    $annot = $result[0];
    $this->assertEquals("Some name", $annot->name);
    $this->assertEquals("Some data", $annot->data);
    $docblock = <<<DOCBLOCK
/**
 * @SomeAnnotationClassNameWithoutConstructorAndProperties()
 */
DOCBLOCK;
    $result = $parser->parse($docblock);
    $this->assertCount(1, $result);
    $this->assertInstanceOf(SomeAnnotationClassNameWithoutConstructorAndProperties::class, $result[0]);
}

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