Skip to content

Commit 3587ab5

Browse files
authored
Merge pull request #461 from doctrine/1.13.x
Merge 1.13.x up into 1.14.x
2 parents 23bf490 + 99a390a commit 3587ab5

File tree

4 files changed

+79
-0
lines changed

4 files changed

+79
-0
lines changed

tests/Doctrine/Tests/Common/Annotations/AnnotationReaderTest.php

+34
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
use Doctrine\Common\Annotations\DocParser;
77
use Doctrine\Common\Annotations\Reader;
88
use Doctrine\Tests\Common\Annotations\Fixtures\Annotation\SingleUseAnnotation;
9+
use Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithEnumProperty;
10+
use Doctrine\Tests\Common\Annotations\Fixtures\ClassWithEnumAnnotations;
911
use Doctrine\Tests\Common\Annotations\Fixtures\ClassWithFullPathUseStatement;
1012
use Doctrine\Tests\Common\Annotations\Fixtures\ClassWithImportedIgnoredAnnotation;
1113
use Doctrine\Tests\Common\Annotations\Fixtures\ClassWithPHPCodeSnifferAnnotation;
@@ -15,6 +17,7 @@
1517
use Doctrine\Tests\Common\Annotations\Fixtures\IgnoredNamespaces\AnnotatedAtMethodLevel;
1618
use Doctrine\Tests\Common\Annotations\Fixtures\IgnoredNamespaces\AnnotatedAtPropertyLevel;
1719
use Doctrine\Tests\Common\Annotations\Fixtures\IgnoredNamespaces\AnnotatedWithAlias;
20+
use Doctrine\Tests\Common\Annotations\Fixtures\Suit;
1821
use InvalidArgumentException;
1922
use LogicException;
2023
use ReflectionClass;
@@ -24,6 +27,8 @@
2427
use function spl_autoload_register;
2528
use function spl_autoload_unregister;
2629

30+
use const PHP_VERSION_ID;
31+
2732
class AnnotationReaderTest extends AbstractReaderTest
2833
{
2934
/**
@@ -295,4 +300,33 @@ public function testFunctionAnnotation(): void
295300
$annotation = $reader->getFunctionAnnotation($ref, Fixtures\Annotation\Autoload::class);
296301
self::assertInstanceOf(Fixtures\Annotation\Autoload::class, $annotation);
297302
}
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+
}
298332
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\Tests\Common\Annotations\Fixtures;
6+
7+
/**
8+
* @Annotation
9+
* @Target("ALL")
10+
* @NamedArgumentConstructor
11+
*/
12+
final class AnnotationWithEnumProperty
13+
{
14+
public function __construct(
15+
public readonly Suit $suit = Suit::Hearts,
16+
) {
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\Tests\Common\Annotations\Fixtures;
6+
7+
class ClassWithEnumAnnotations
8+
{
9+
/** @AnnotationWithEnumProperty */
10+
public mixed $annotationWithDefaults;
11+
12+
/** @AnnotationWithEnumProperty(suit=Suit::Spades) */
13+
public mixed $annotationWithSpades;
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\Tests\Common\Annotations\Fixtures;
6+
7+
enum Suit
8+
{
9+
case Hearts;
10+
case Diamonds;
11+
case Clubs;
12+
case Spades;
13+
}

0 commit comments

Comments
 (0)