diff --git a/ModelDescriber/EnumModelDescriber.php b/ModelDescriber/EnumModelDescriber.php index 41fba6e42..93ad24fb1 100644 --- a/ModelDescriber/EnumModelDescriber.php +++ b/ModelDescriber/EnumModelDescriber.php @@ -17,7 +17,12 @@ public function describe(Model $model, Schema $schema) $enums[] = $enumCase->value; } - $schema->type = is_subclass_of($enumClass, \IntBackedEnum::class) ? 'int' : 'string'; + $reflectionEnum = new \ReflectionEnum($enumClass); + if ($reflectionEnum->isBacked() && 'int' === $reflectionEnum->getBackingType()->getName()) { + $schema->type = 'integer'; + } else { + $schema->type = 'string'; + } $schema->enum = $enums; } diff --git a/Tests/Functional/Entity/Article81.php b/Tests/Functional/Entity/Article81.php index 390480183..8a483cd79 100644 --- a/Tests/Functional/Entity/Article81.php +++ b/Tests/Functional/Entity/Article81.php @@ -7,6 +7,8 @@ class Article81 public function __construct( public readonly int $id, public readonly ArticleType81 $type, + public readonly ArticleType81IntBacked $intBackedType, + public readonly ArticleType81NotBacked $notBackedType, ) { } } diff --git a/Tests/Functional/Entity/ArticleType81IntBacked.php b/Tests/Functional/Entity/ArticleType81IntBacked.php new file mode 100644 index 000000000..1d1f243d8 --- /dev/null +++ b/Tests/Functional/Entity/ArticleType81IntBacked.php @@ -0,0 +1,9 @@ +assertSame('string', $model->type); $this->assertCount(2, $model->enum); + + $model = $this->getModel('ArticleType81NotBacked'); + + $this->assertSame('object', $model->type, 'Non backed enums cannot be described'); + + $model = $this->getModel('ArticleType81IntBacked'); + + $this->assertSame('integer', $model->type); + $this->assertCount(2, $model->enum); } public function testEntitiesWithOverriddenSchemaTypeDoNotReadOtherProperties()