diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index d736886563c..bb6ea466ee5 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -1493,6 +1493,10 @@ private function validateAndCompleteTypedFieldMapping(array $mapping): array case 'string': $mapping['type'] = Types::STRING; break; + default: + if (PHP_VERSION_ID >= 80100 && enum_exists($type->getName())) { + $mapping['type'] = Types::ENUM; + } } } } diff --git a/tests/Doctrine/Tests/Models/TypedProperties/Article.php b/tests/Doctrine/Tests/Models/TypedProperties/Article.php new file mode 100644 index 00000000000..5a9baeb0845 --- /dev/null +++ b/tests/Doctrine/Tests/Models/TypedProperties/Article.php @@ -0,0 +1,17 @@ +getTypeOfField('float')); } + public function testFieldTypeEnumFromReflection(): void + { + if (PHP_VERSION_ID < 80100) { + self::markTestSkipped('requires PHP 8.1'); + } + + $cm = new ClassMetadata(TypedProperties\Article::class); + $cm->initializeReflection(new RuntimeReflectionService()); + + $cm->mapField(['fieldName' => 'enum']); + self::assertEquals('enum', $cm->getTypeOfField('enum')); + } + /** * @group DDC-115 */