Skip to content

Commit fd865da

Browse files
committed
remove support of non backed enums
1 parent 7ed37e6 commit fd865da

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

src/Symfony/Component/SerDes/Internal/TypeFactory.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,12 @@ public static function createFromString(string $string): Type|UnionType
110110
return self::$cache[$cacheKey] = new Type($string, $isNullable);
111111
}
112112

113-
if (is_subclass_of($string, \BackedEnum::class)) {
114-
return self::$cache[$cacheKey] = new Type('enum', $isNullable, $string);
113+
if (is_subclass_of($string, \UnitEnum::class)) {
114+
if (is_subclass_of($string, \BackedEnum::class)) {
115+
return self::$cache[$cacheKey] = new Type('enum', $isNullable, $string);
116+
}
117+
118+
throw new InvalidTypeException($string);
115119
}
116120

117121
if (class_exists($string) || interface_exists($string)) {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace Symfony\Component\SerDes\Tests\Fixtures\Enum;
4+
5+
enum DummyUnitEnum
6+
{
7+
case ONE;
8+
case TWO;
9+
}

src/Symfony/Component/SerDes/Tests/Internal/TypeFactoryTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Symfony\Component\SerDes\Internal\UnionType;
2121
use Symfony\Component\SerDes\Tests\Fixtures\Dto\ClassicDummy;
2222
use Symfony\Component\SerDes\Tests\Fixtures\Enum\DummyBackedEnum;
23+
use Symfony\Component\SerDes\Tests\Fixtures\Enum\DummyUnitEnum;
2324

2425
class TypeFactoryTest extends TestCase
2526
{
@@ -140,4 +141,11 @@ public function testCreateThrowOnRawArray()
140141

141142
TypeFactory::createFromString('array');
142143
}
144+
145+
public function testCreateThrowOnUnitEnum()
146+
{
147+
$this->expectException(InvalidTypeException::class);
148+
149+
TypeFactory::createFromString(DummyUnitEnum::class);
150+
}
143151
}

0 commit comments

Comments
 (0)