From 99a390abd668fa52c022a11a220ca4460f48fd85 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Wed, 26 Oct 2022 10:01:44 +0200 Subject: [PATCH] Added test cases for enums (#459) --- .../Annotations/AnnotationReaderTest.php | 34 +++++++++++++++++++ .../Fixtures/AnnotationWithEnumProperty.php | 18 ++++++++++ .../Fixtures/ClassWithEnumAnnotations.php | 14 ++++++++ .../Common/Annotations/Fixtures/Suit.php | 13 +++++++ 4 files changed, 79 insertions(+) create mode 100644 tests/Doctrine/Tests/Common/Annotations/Fixtures/AnnotationWithEnumProperty.php create mode 100644 tests/Doctrine/Tests/Common/Annotations/Fixtures/ClassWithEnumAnnotations.php create mode 100644 tests/Doctrine/Tests/Common/Annotations/Fixtures/Suit.php diff --git a/tests/Doctrine/Tests/Common/Annotations/AnnotationReaderTest.php b/tests/Doctrine/Tests/Common/Annotations/AnnotationReaderTest.php index 5c8754295..04ffe1b37 100644 --- a/tests/Doctrine/Tests/Common/Annotations/AnnotationReaderTest.php +++ b/tests/Doctrine/Tests/Common/Annotations/AnnotationReaderTest.php @@ -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; @@ -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; @@ -24,6 +27,8 @@ use function spl_autoload_register; use function spl_autoload_unregister; +use const PHP_VERSION_ID; + class AnnotationReaderTest extends AbstractReaderTest { /** @@ -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 + */ + public function provideEnumProperties(): array + { + if (PHP_VERSION_ID < 80100) { + return []; + } + + return [ + 'annotationWithDefaults' => ['annotationWithDefaults', Suit::Hearts], + 'annotationWithSpades' => ['annotationWithSpades', Suit::Spades], + ]; + } } diff --git a/tests/Doctrine/Tests/Common/Annotations/Fixtures/AnnotationWithEnumProperty.php b/tests/Doctrine/Tests/Common/Annotations/Fixtures/AnnotationWithEnumProperty.php new file mode 100644 index 000000000..97d299769 --- /dev/null +++ b/tests/Doctrine/Tests/Common/Annotations/Fixtures/AnnotationWithEnumProperty.php @@ -0,0 +1,18 @@ +