|
6 | 6 | use Doctrine\Common\Annotations\DocParser;
|
7 | 7 | use Doctrine\Common\Annotations\Reader;
|
8 | 8 | use Doctrine\Tests\Common\Annotations\Fixtures\Annotation\SingleUseAnnotation;
|
| 9 | +use Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithEnumProperty; |
| 10 | +use Doctrine\Tests\Common\Annotations\Fixtures\ClassWithEnumAnnotations; |
9 | 11 | use Doctrine\Tests\Common\Annotations\Fixtures\ClassWithFullPathUseStatement;
|
10 | 12 | use Doctrine\Tests\Common\Annotations\Fixtures\ClassWithImportedIgnoredAnnotation;
|
11 | 13 | use Doctrine\Tests\Common\Annotations\Fixtures\ClassWithPHPCodeSnifferAnnotation;
|
|
15 | 17 | use Doctrine\Tests\Common\Annotations\Fixtures\IgnoredNamespaces\AnnotatedAtMethodLevel;
|
16 | 18 | use Doctrine\Tests\Common\Annotations\Fixtures\IgnoredNamespaces\AnnotatedAtPropertyLevel;
|
17 | 19 | use Doctrine\Tests\Common\Annotations\Fixtures\IgnoredNamespaces\AnnotatedWithAlias;
|
| 20 | +use Doctrine\Tests\Common\Annotations\Fixtures\Suit; |
18 | 21 | use InvalidArgumentException;
|
19 | 22 | use LogicException;
|
20 | 23 | use ReflectionClass;
|
|
24 | 27 | use function spl_autoload_register;
|
25 | 28 | use function spl_autoload_unregister;
|
26 | 29 |
|
| 30 | +use const PHP_VERSION_ID; |
| 31 | + |
27 | 32 | class AnnotationReaderTest extends AbstractReaderTest
|
28 | 33 | {
|
29 | 34 | /**
|
@@ -295,4 +300,33 @@ public function testFunctionAnnotation(): void
|
295 | 300 | $annotation = $reader->getFunctionAnnotation($ref, Fixtures\Annotation\Autoload::class);
|
296 | 301 | self::assertInstanceOf(Fixtures\Annotation\Autoload::class, $annotation);
|
297 | 302 | }
|
| 303 | + |
| 304 | + /** |
| 305 | + * @requires PHP 8.1 |
| 306 | + * @dataProvider provideEnumProperties |
| 307 | + */ |
| 308 | + public function testAnnotationWithEnum(string $property, Suit $expectedValue): void |
| 309 | + { |
| 310 | + $reader = $this->getReader(); |
| 311 | + $ref = new ReflectionClass(ClassWithEnumAnnotations::class); |
| 312 | + |
| 313 | + $annotation = $reader->getPropertyAnnotation($ref->getProperty($property), AnnotationWithEnumProperty::class); |
| 314 | + |
| 315 | + self::assertSame($expectedValue, $annotation->suit); |
| 316 | + } |
| 317 | + |
| 318 | + /** |
| 319 | + * @return array<string, array{string, Suit}> |
| 320 | + */ |
| 321 | + public function provideEnumProperties(): array |
| 322 | + { |
| 323 | + if (PHP_VERSION_ID < 80100) { |
| 324 | + return []; |
| 325 | + } |
| 326 | + |
| 327 | + return [ |
| 328 | + 'annotationWithDefaults' => ['annotationWithDefaults', Suit::Hearts], |
| 329 | + 'annotationWithSpades' => ['annotationWithSpades', Suit::Spades], |
| 330 | + ]; |
| 331 | + } |
298 | 332 | }
|
0 commit comments