function DocParserTest::testAnnotationWithoutConstructor

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()
  2. 8.9.x core/tests/Drupal/Tests/Component/Annotation/Doctrine/DocParserTest.php \Drupal\Tests\Component\Annotation\Doctrine\DocParserTest::testAnnotationWithoutConstructor()
  3. 10 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
This class is a near-copy of Doctrine\Tests\Common\Annotations\DocParserTest, which is part of the Doctrine project: &lt;<a href="http://www.doctrine-project.org&amp;gt">http://www.doctrine-project.org&amp;gt</a>;. It was copied from version 1.2.7.

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.