File tree Expand file tree Collapse file tree 3 files changed +23
-2
lines changed
src/Symfony/Component/SerDes Expand file tree Collapse file tree 3 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -110,8 +110,12 @@ public static function createFromString(string $string): Type|UnionType
110
110
return self ::$ cache [$ cacheKey ] = new Type ($ string , $ isNullable );
111
111
}
112
112
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 );
115
119
}
116
120
117
121
if (class_exists ($ string ) || interface_exists ($ string )) {
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Symfony \Component \SerDes \Tests \Fixtures \Enum ;
4
+
5
+ enum DummyUnitEnum
6
+ {
7
+ case ONE ;
8
+ case TWO ;
9
+ }
Original file line number Diff line number Diff line change 20
20
use Symfony \Component \SerDes \Internal \UnionType ;
21
21
use Symfony \Component \SerDes \Tests \Fixtures \Dto \ClassicDummy ;
22
22
use Symfony \Component \SerDes \Tests \Fixtures \Enum \DummyBackedEnum ;
23
+ use Symfony \Component \SerDes \Tests \Fixtures \Enum \DummyUnitEnum ;
23
24
24
25
class TypeFactoryTest extends TestCase
25
26
{
@@ -140,4 +141,11 @@ public function testCreateThrowOnRawArray()
140
141
141
142
TypeFactory::createFromString ('array ' );
142
143
}
144
+
145
+ public function testCreateThrowOnUnitEnum ()
146
+ {
147
+ $ this ->expectException (InvalidTypeException::class);
148
+
149
+ TypeFactory::createFromString (DummyUnitEnum::class);
150
+ }
143
151
}
You can’t perform that action at this time.
0 commit comments