|
19 | 19 | use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory; |
20 | 20 | use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader; |
21 | 21 | use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer; |
| 22 | +use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; |
22 | 23 | use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; |
23 | 24 | use Symfony\Component\Serializer\SerializerAwareInterface; |
24 | 25 | use Symfony\Component\Serializer\SerializerInterface; |
@@ -52,7 +53,8 @@ public function testInstantiateObjectDenormalizer() |
52 | 53 | */ |
53 | 54 | public function testDenormalizeWithExtraAttributes() |
54 | 55 | { |
55 | | - $normalizer = new AbstractObjectNormalizerDummy(); |
| 56 | + $factory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader())); |
| 57 | + $normalizer = new AbstractObjectNormalizerDummy($factory); |
56 | 58 | $normalizer->denormalize( |
57 | 59 | array('fooFoo' => 'foo', 'fooBar' => 'bar'), |
58 | 60 | __NAMESPACE__.'\Dummy', |
@@ -144,6 +146,23 @@ private function getDenormalizerForDummyCollection() |
144 | 146 |
|
145 | 147 | return $denormalizer; |
146 | 148 | } |
| 149 | + |
| 150 | + /** |
| 151 | + * Test that additional attributes throw an exception if no metadata factory is specified. |
| 152 | + * |
| 153 | + * @see https://symfony.com/doc/current/components/serializer.html#deserializing-an-object |
| 154 | + * |
| 155 | + * @expectedException \Symfony\Component\Serializer\Exception\LogicException |
| 156 | + * @expectedExceptionMessage A class metadata factory must be provided in the constructor when setting 'allow_extra_attributes' to false. |
| 157 | + */ |
| 158 | + public function testExtraAttributesException() |
| 159 | + { |
| 160 | + $normalizer = new ObjectNormalizer(); |
| 161 | + |
| 162 | + $normalizer->denormalize(array(), \stdClass::class, 'xml', array( |
| 163 | + 'allow_extra_attributes' => false, |
| 164 | + )); |
| 165 | + } |
147 | 166 | } |
148 | 167 |
|
149 | 168 | class AbstractObjectNormalizerDummy extends AbstractObjectNormalizer |
|
0 commit comments