|
20 | 20 | use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
|
21 | 21 | use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface;
|
22 | 22 | use Symfony\Component\Serializer\Mapping\Loader\LoaderChain;
|
| 23 | +use Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter; |
23 | 24 | use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
|
24 | 25 | use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
|
25 | 26 | use Symfony\Component\Serializer\Normalizer\PropertyNormalizer;
|
|
29 | 30 | use Symfony\Component\Serializer\Tests\Fixtures\Dummy;
|
30 | 31 | use Symfony\Component\Serializer\Tests\Fixtures\NullableConstructorArgumentDummy;
|
31 | 32 | use Symfony\Component\Serializer\Tests\Fixtures\NullableOptionalConstructorArgumentDummy;
|
| 33 | +use Symfony\Component\Serializer\Tests\Fixtures\Php80ReadonlyDummy; |
32 | 34 | use Symfony\Component\Serializer\Tests\Fixtures\StaticConstructorDummy;
|
33 | 35 | use Symfony\Component\Serializer\Tests\Fixtures\StaticConstructorNormalizer;
|
34 | 36 | use Symfony\Component\Serializer\Tests\Fixtures\VariadicConstructorTypedArgsDummy;
|
@@ -233,6 +235,19 @@ public function testVariadicSerializationWithPreservingKeys(AbstractNormalizer $
|
233 | 235 | $this->assertEquals($arr, $dummy->getFoo());
|
234 | 236 | }
|
235 | 237 |
|
| 238 | + /** |
| 239 | + * @requires PHP 8 |
| 240 | + */ |
| 241 | + public function testWithNameConverter() |
| 242 | + { |
| 243 | + $normalizer = new ObjectNormalizer(null, new CamelCaseToSnakeCaseNameConverter()); |
| 244 | + |
| 245 | + $object = new Php80ReadonlyDummy('foo'); |
| 246 | + $this->assertEquals(['some_value' => 'foo'], $normalizer->normalize($object)); |
| 247 | + $this->assertEquals($object, $normalizer->denormalize(['some_value' => 'foo'], Php80ReadonlyDummy::class)); |
| 248 | + $this->assertEquals($object, $normalizer->denormalize(['someValue' => 'foo'], Php80ReadonlyDummy::class)); |
| 249 | + } |
| 250 | + |
236 | 251 | public static function getNormalizer()
|
237 | 252 | {
|
238 | 253 | $extractor = new PhpDocExtractor();
|
|
0 commit comments