Skip to content

Commit

Permalink
Merge pull request #461 from doctrine/1.13.x
Browse files Browse the repository at this point in the history
Merge 1.13.x up into 1.14.x
  • Loading branch information
greg0ire committed Dec 11, 2022
2 parents 23bf490 + 99a390a commit 3587ab5
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/Doctrine/Tests/Common/Annotations/AnnotationReaderTest.php
Expand Up @@ -6,6 +6,8 @@
use Doctrine\Common\Annotations\DocParser;
use Doctrine\Common\Annotations\Reader;
use Doctrine\Tests\Common\Annotations\Fixtures\Annotation\SingleUseAnnotation;
use Doctrine\Tests\Common\Annotations\Fixtures\AnnotationWithEnumProperty;
use Doctrine\Tests\Common\Annotations\Fixtures\ClassWithEnumAnnotations;
use Doctrine\Tests\Common\Annotations\Fixtures\ClassWithFullPathUseStatement;
use Doctrine\Tests\Common\Annotations\Fixtures\ClassWithImportedIgnoredAnnotation;
use Doctrine\Tests\Common\Annotations\Fixtures\ClassWithPHPCodeSnifferAnnotation;
Expand All @@ -15,6 +17,7 @@
use Doctrine\Tests\Common\Annotations\Fixtures\IgnoredNamespaces\AnnotatedAtMethodLevel;
use Doctrine\Tests\Common\Annotations\Fixtures\IgnoredNamespaces\AnnotatedAtPropertyLevel;
use Doctrine\Tests\Common\Annotations\Fixtures\IgnoredNamespaces\AnnotatedWithAlias;
use Doctrine\Tests\Common\Annotations\Fixtures\Suit;
use InvalidArgumentException;
use LogicException;
use ReflectionClass;
Expand All @@ -24,6 +27,8 @@
use function spl_autoload_register;
use function spl_autoload_unregister;

use const PHP_VERSION_ID;

class AnnotationReaderTest extends AbstractReaderTest
{
/**
Expand Down Expand Up @@ -295,4 +300,33 @@ public function testFunctionAnnotation(): void
$annotation = $reader->getFunctionAnnotation($ref, Fixtures\Annotation\Autoload::class);
self::assertInstanceOf(Fixtures\Annotation\Autoload::class, $annotation);
}

/**
* @requires PHP 8.1
* @dataProvider provideEnumProperties
*/
public function testAnnotationWithEnum(string $property, Suit $expectedValue): void
{
$reader = $this->getReader();
$ref = new ReflectionClass(ClassWithEnumAnnotations::class);

$annotation = $reader->getPropertyAnnotation($ref->getProperty($property), AnnotationWithEnumProperty::class);

self::assertSame($expectedValue, $annotation->suit);
}

/**
* @return array<string, array{string, Suit}>
*/
public function provideEnumProperties(): array
{
if (PHP_VERSION_ID < 80100) {
return [];
}

return [
'annotationWithDefaults' => ['annotationWithDefaults', Suit::Hearts],
'annotationWithSpades' => ['annotationWithSpades', Suit::Spades],
];
}
}
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Doctrine\Tests\Common\Annotations\Fixtures;

/**
* @Annotation
* @Target("ALL")
* @NamedArgumentConstructor
*/
final class AnnotationWithEnumProperty
{
public function __construct(
public readonly Suit $suit = Suit::Hearts,
) {
}
}
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace Doctrine\Tests\Common\Annotations\Fixtures;

class ClassWithEnumAnnotations
{
/** @AnnotationWithEnumProperty */
public mixed $annotationWithDefaults;

/** @AnnotationWithEnumProperty(suit=Suit::Spades) */
public mixed $annotationWithSpades;
}
13 changes: 13 additions & 0 deletions tests/Doctrine/Tests/Common/Annotations/Fixtures/Suit.php
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Doctrine\Tests\Common\Annotations\Fixtures;

enum Suit
{
case Hearts;
case Diamonds;
case Clubs;
case Spades;
}

0 comments on commit 3587ab5

Please sign in to comment.