|
11 | 11 |
|
12 | 12 | namespace Symfony\Component\Serializer\Tests\Normalizer; |
13 | 13 |
|
| 14 | +use Doctrine\Common\Annotations\AnnotationReader; |
14 | 15 | use PHPUnit\Framework\TestCase; |
| 16 | +use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory; |
| 17 | +use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader; |
15 | 18 | use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer; |
16 | 19 |
|
17 | 20 | class AbstractObjectNormalizerTest extends TestCase |
@@ -51,6 +54,21 @@ public function testDenormalizeWithExtraAttributes() |
51 | 54 | array('allow_extra_attributes' => false) |
52 | 55 | ); |
53 | 56 | } |
| 57 | + |
| 58 | + /** |
| 59 | + * @expectedException \Symfony\Component\Serializer\Exception\ExtraAttributesException |
| 60 | + * @expectedExceptionMessage Extra attributes are not allowed ("fooFoo", "fooBar" are unknown). |
| 61 | + */ |
| 62 | + public function testDenormalizeWithExtraAttributesAndNoGroupsWithMetadataFactory() |
| 63 | + { |
| 64 | + $normalizer = new AbstractObjectNormalizerWithMetadata(); |
| 65 | + $normalizer->denormalize( |
| 66 | + array('fooFoo' => 'foo', 'fooBar' => 'bar', 'bar' => 'bar'), |
| 67 | + Dummy::class, |
| 68 | + 'any', |
| 69 | + array('allow_extra_attributes' => false) |
| 70 | + ); |
| 71 | + } |
54 | 72 | } |
55 | 73 |
|
56 | 74 | class AbstractObjectNormalizerDummy extends AbstractObjectNormalizer |
@@ -85,3 +103,24 @@ class Dummy |
85 | 103 | public $bar; |
86 | 104 | public $baz; |
87 | 105 | } |
| 106 | + |
| 107 | +class AbstractObjectNormalizerWithMetadata extends AbstractObjectNormalizer |
| 108 | +{ |
| 109 | + public function __construct() |
| 110 | + { |
| 111 | + parent::__construct(new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()))); |
| 112 | + } |
| 113 | + |
| 114 | + protected function extractAttributes($object, $format = null, array $context = array()) |
| 115 | + { |
| 116 | + } |
| 117 | + |
| 118 | + protected function getAttributeValue($object, $attribute, $format = null, array $context = array()) |
| 119 | + { |
| 120 | + } |
| 121 | + |
| 122 | + protected function setAttributeValue($object, $attribute, $value, $format = null, array $context = array()) |
| 123 | + { |
| 124 | + $object->$attribute = $value; |
| 125 | + } |
| 126 | +} |
0 commit comments