Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge 1.13.x up into 1.14.x #461

Merged
merged 1 commit into from Dec 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
}