File tree Expand file tree Collapse file tree 3 files changed +43
-0
lines changed
src/Bundle/Resources/config Expand file tree Collapse file tree 3 files changed +43
-0
lines changed Original file line number Diff line number Diff line change 15
15
16
16
<service id =" dunglas_doctrine_json_odm.normalizer.array" class =" Symfony\Component\Serializer\Normalizer\ArrayDenormalizer" public =" false" />
17
17
18
+ <service id =" dunglas_doctrine_json_odm.normalizer.backed_enum" class =" Symfony\Component\Serializer\Normalizer\BackedEnumNormalizer" public =" false" />
19
+
18
20
<service id =" dunglas_doctrine_json_odm.serializer" class =" Dunglas\DoctrineJsonOdm\Serializer" public =" true" >
19
21
<argument type =" collection" >
22
+ <argument type =" service" id =" dunglas_doctrine_json_odm.normalizer.backed_enum" />
20
23
<argument type =" service" id =" dunglas_doctrine_json_odm.normalizer.array" />
21
24
<argument type =" service" id =" dunglas_doctrine_json_odm.normalizer.object" />
22
25
</argument >
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ /*
4
+ * (c) Kévin Dunglas <[email protected] >
5
+ *
6
+ * This source file is subject to the MIT license that is bundled
7
+ * with this source code in the file LICENSE.
8
+ */
9
+
10
+ namespace Dunglas \DoctrineJsonOdm \Tests \Fixtures \TestBundle \Enum ;
11
+
12
+ enum InputMode: string
13
+ {
14
+ case EMAIL = 'email ' ;
15
+ }
Original file line number Diff line number Diff line change 16
16
use Dunglas \DoctrineJsonOdm \Tests \Fixtures \TestBundle \Document \ScalarValue ;
17
17
use Dunglas \DoctrineJsonOdm \Tests \Fixtures \TestBundle \Entity \Foo ;
18
18
use Dunglas \DoctrineJsonOdm \Tests \Fixtures \TestBundle \Entity \Product ;
19
+ use Dunglas \DoctrineJsonOdm \Tests \Fixtures \TestBundle \Enum \InputMode ;
19
20
use Symfony \Component \Console \Input \StringInput ;
20
21
21
22
/**
@@ -192,4 +193,28 @@ public function testStoreAndRetrieveDocumentWithInstantiatedOtherSerializer(): v
192
193
$ retrievedProduct = $ manager ->find (Product::class, $ product ->id );
193
194
$ this ->assertEquals ($ attributes , $ retrievedProduct ->attributes );
194
195
}
196
+
197
+ /**
198
+ * @requires PHP 8.1
199
+ */
200
+ public function testStoreAndRetrieveEnum (): void
201
+ {
202
+ $ attribute = new Attribute ();
203
+ $ attribute ->key = 'email ' ;
204
+ $ attribute ->value = InputMode::EMAIL ;
205
+
206
+ $ product = new Product ();
207
+ $ product ->name = 'My product ' ;
208
+ $ product ->attributes = [$ attribute ];
209
+
210
+ $ manager = self ::$ kernel ->getContainer ()->get ('doctrine ' )->getManagerForClass (Product::class);
211
+ $ manager ->persist ($ product );
212
+ $ manager ->flush ();
213
+
214
+ $ manager ->clear ();
215
+
216
+ $ retrievedProduct = $ manager ->find (Product::class, $ product ->id );
217
+
218
+ $ this ->assertSame (InputMode::EMAIL , $ retrievedProduct ->attributes [0 ]->value );
219
+ }
195
220
}
You can’t perform that action at this time.
0 commit comments