Skip to content

Commit

Permalink
Allow usage of self:: accessor for constants
Browse files Browse the repository at this point in the history
ex: @annotation(self::VALUE)
Fixes doctrine#269
  • Loading branch information
bertrandseurot committed Oct 2, 2020
1 parent 2dceb19 commit c3a707b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/Doctrine/Common/Annotations/AnnotationReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,10 @@ private function collectParsingMetadata(ReflectionClass $class)
$this->imports[$name] = array_merge(
self::$globalImports,
$this->phpParser->parseClass($class),
['__NAMESPACE__' => $class->getNamespaceName()]
[
'__NAMESPACE__' => $class->getNamespaceName(),
'self' => $name,
]
);

$this->ignoredAnnotationNames[$name] = $ignoredAnnotationNames;
Expand Down
14 changes: 14 additions & 0 deletions tests/Doctrine/Tests/Common/Annotations/DocParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,20 @@ public function testSupportClassConstants(string $docblock, $expected): void
self::assertEquals($expected, $annotation->value);
}

public function testSupportSelfAccessorForClassConstants(): void
{
$parser = $this->createTestParser();
$dockBlock = '@AnnotationWithConstants(self::SOME_VALUE)';
$parser->setImports([
'annotationwithconstants' => AnnotationWithConstants::class,
'self' => ClassWithConstants::class,
]);

$result = $parser->parse($dockBlock);
self::assertInstanceOf(AnnotationWithConstants::class, $annotation = $result[0]);
self::assertEquals(ClassWithConstants::SOME_VALUE, $annotation->value);
}

public function testWithoutConstructorWhenIsNotDefaultValue(): void
{
$parser = $this->createTestParser();
Expand Down

0 comments on commit c3a707b

Please sign in to comment.