function DocParserTest::testBasicAnnotations
Same name in other branches
- 9 core/tests/Drupal/Tests/Component/Annotation/Doctrine/DocParserTest.php \Drupal\Tests\Component\Annotation\Doctrine\DocParserTest::testBasicAnnotations()
- 8.9.x core/tests/Drupal/Tests/Component/Annotation/Doctrine/DocParserTest.php \Drupal\Tests\Component\Annotation\Doctrine\DocParserTest::testBasicAnnotations()
- 10 core/tests/Drupal/Tests/Component/Annotation/Doctrine/DocParserTest.php \Drupal\Tests\Component\Annotation\Doctrine\DocParserTest::testBasicAnnotations()
File
-
core/
tests/ Drupal/ Tests/ Component/ Annotation/ Doctrine/ DocParserTest.php, line 51
Class
- DocParserTest
- This class is a near-copy of Doctrine\Tests\Common\Annotations\DocParserTest, which is part of the Doctrine project: <http://www.doctrine-project.org>. It was copied from version 1.2.7.
Namespace
Drupal\Tests\Component\Annotation\DoctrineCode
public function testBasicAnnotations() : void {
$parser = $this->createTestParser();
// Marker annotation
$result = $parser->parse("@Name");
$annot = $result[0];
$this->assertInstanceOf(Name::class, $annot);
$this->assertNull($annot->value);
$this->assertNull($annot->foo);
// Associative arrays
$result = $parser->parse('@Name(foo={"key1" = "value1"})');
$annot = $result[0];
$this->assertNull($annot->value);
$this->assertIsArray($annot->foo);
$this->assertTrue(isset($annot->foo['key1']));
// Numerical arrays
$result = $parser->parse('@Name({2="foo", 4="bar"})');
$annot = $result[0];
$this->assertIsArray($annot->value);
$this->assertEquals('foo', $annot->value[2]);
$this->assertEquals('bar', $annot->value[4]);
$this->assertFalse(isset($annot->value[0]));
$this->assertFalse(isset($annot->value[1]));
$this->assertFalse(isset($annot->value[3]));
// Multiple values
$result = $parser->parse('@Name(@Name, @Name)');
$annot = $result[0];
$this->assertInstanceOf(Name::class, $annot);
$this->assertIsArray($annot->value);
$this->assertInstanceOf(Name::class, $annot->value[0]);
$this->assertInstanceOf(Name::class, $annot->value[1]);
// Multiple types as values
$result = $parser->parse('@Name(foo="Bar", @Name, {"key1"="value1", "key2"="value2"})');
$annot = $result[0];
$this->assertInstanceOf(Name::class, $annot);
$this->assertIsArray($annot->value);
$this->assertInstanceOf(Name::class, $annot->value[0]);
$this->assertIsArray($annot->value[1]);
$this->assertEquals('value1', $annot->value[1]['key1']);
$this->assertEquals('value2', $annot->value[1]['key2']);
// Complete docblock
$docblock = <<<DOCBLOCK
/**
* Some nifty class.
*
* @author Mr.X
* @Name(foo="bar")
*/
DOCBLOCK;
$result = $parser->parse($docblock);
$this->assertCount(1, $result);
$annot = $result[0];
$this->assertInstanceOf(Name::class, $annot);
$this->assertEquals("bar", $annot->foo);
$this->assertNull($annot->value);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.