From f5bd990ccf47b4bd78c04f45b84a0945b74e7353 Mon Sep 17 00:00:00 2001 From: Yonel Ceruto Date: Thu, 14 Dec 2023 15:21:32 -0500 Subject: [PATCH] Fixed enum mapping validation --- lib/Doctrine/ORM/Tools/SchemaValidator.php | 19 +++++++++++++++++++ .../Ticket/GH11037/EntityStatus.php | 9 +++++++++ .../Functional/Ticket/GH11037/GH11037Test.php | 1 + .../GH11037/InvalidEntityWithTypedEnum.php | 5 +++++ .../Ticket/GH11037/StringEntityStatus.php | 2 +- .../GH11037/ValidEntityWithTypedEnum.php | 5 +++++ 6 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/GH11037/EntityStatus.php diff --git a/lib/Doctrine/ORM/Tools/SchemaValidator.php b/lib/Doctrine/ORM/Tools/SchemaValidator.php index fbaf33bd01d..d5ad91a1770 100644 --- a/lib/Doctrine/ORM/Tools/SchemaValidator.php +++ b/lib/Doctrine/ORM/Tools/SchemaValidator.php @@ -406,6 +406,25 @@ function (array $fieldMapping) use ($class): ?string { ); } + if ( + isset($fieldMapping['enumType']) + && $propertyType !== $fieldMapping['enumType'] + && interface_exists($propertyType) + && is_a($fieldMapping['enumType'], $propertyType, true) + ) { + if ($metadataFieldType === (string) (new ReflectionEnum($fieldMapping['enumType']))->getBackingType()) { + return null; + } + + return sprintf( + "The field '%s#%s' has the metadata enumType '%s' that differs from the metadata field type '%s'.", + $class->name, + $fieldName, + $fieldMapping['enumType'], + $metadataFieldType + ); + } + if ( $fieldMapping['type'] === 'json' && in_array($propertyType, ['string', 'int', 'float', 'bool', 'true', 'false', 'null'], true) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH11037/EntityStatus.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH11037/EntityStatus.php new file mode 100644 index 00000000000..f94c44affe0 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH11037/EntityStatus.php @@ -0,0 +1,9 @@ +