|
16 | 16 | useSymfony\Component\PropertyInfo\Extractor\PhpDocExtractor; |
17 | 17 | useSymfony\Component\PropertyInfo\Type; |
18 | 18 | useSymfony\Component\Serializer\Annotation\SerializedName; |
19 | | -useSymfony\Component\Serializer\Encoder\JsonEncoder; |
20 | | -useSymfony\Component\Serializer\Encoder\XmlEncoder; |
21 | 19 | useSymfony\Component\Serializer\Exception\ExtraAttributesException; |
22 | 20 | useSymfony\Component\Serializer\Exception\InvalidArgumentException; |
23 | 21 | useSymfony\Component\Serializer\Exception\LogicException; |
@@ -106,146 +104,146 @@ public function testDenormalizeWithExtraAttributesAndNoGroupsWithMetadataFactory |
106 | 104 | ); |
107 | 105 | } |
108 | 106 |
|
109 | | -publicfunctiontestDenormalizeWithNestedAttributesAndNoMetadataFactory() |
110 | | -{ |
111 | | -$this->expectException(LogicException::class); |
| 107 | +publicfunctiontestDenormalizeWithNestedAttributesAndNoMetadataFactory() |
| 108 | +{ |
| 109 | +$this->expectException(LogicException::class); |
112 | 110 | $this->expectExceptionMessage('A class metadata factory must be provided in the constructor when setting "flatten_nested_attributes" to true.'); |
113 | | -$normalizer =newObjectNormalizer(); |
114 | | -$normalizer->denormalize( |
115 | | -[], |
116 | | -NestedDummy::class, |
117 | | -'any', |
118 | | -['flatten_nested_attributes' =>true] |
119 | | -); |
120 | | -} |
121 | | - |
122 | | -publicfunctiontestDenormalizeWithDuplicateNestedAttributes() |
123 | | -{ |
124 | | -$this->expectException(LogicException::class); |
| 111 | +$normalizer =newObjectNormalizer(); |
| 112 | +$normalizer->denormalize( |
| 113 | +[], |
| 114 | +NestedDummy::class, |
| 115 | +'any', |
| 116 | +['flatten_nested_attributes' =>true] |
| 117 | +); |
| 118 | +} |
| 119 | + |
| 120 | +publicfunctiontestDenormalizeWithDuplicateNestedAttributes() |
| 121 | +{ |
| 122 | +$this->expectException(LogicException::class); |
125 | 123 | $this->expectExceptionMessage('Duplicate serialized name: "one.two.three"'); |
126 | 124 | $normalizer =newAbstractObjectNormalizerWithMetadata(); |
127 | | -$normalizer->denormalize( |
128 | | -[], |
129 | | -DuplicateNestedDummy::class, |
130 | | -'any', |
131 | | -['flatten_nested_attributes' =>true] |
132 | | -); |
133 | | -} |
134 | | - |
135 | | -publicfunctiontestDenormalizeWithNestedAttributes() |
136 | | -{ |
| 125 | +$normalizer->denormalize( |
| 126 | +[], |
| 127 | +DuplicateNestedDummy::class, |
| 128 | +'any', |
| 129 | +['flatten_nested_attributes' =>true] |
| 130 | +); |
| 131 | +} |
| 132 | + |
| 133 | +publicfunctiontestDenormalizeWithNestedAttributes() |
| 134 | +{ |
137 | 135 | $normalizer =newAbstractObjectNormalizerWithMetadata(); |
138 | | -$data = [ |
139 | | -'one' => [ |
140 | | -'two' => [ |
141 | | -'three' =>'foo' |
142 | | -], |
143 | | -'four' =>'bar' |
144 | | -] |
145 | | -]; |
146 | | -$test =$normalizer->denormalize( |
147 | | -$data, |
148 | | -NestedDummy::class, |
149 | | -'any', |
150 | | -['flatten_nested_attributes' =>true] |
151 | | -); |
152 | | -$this->assertEquals('foo',$test->foo); |
153 | | -$this->assertEquals('bar',$test->bar); |
154 | | -} |
155 | | - |
156 | | -publicfunctiontestNormalizeWithNestedAttributesAndNoMetadataNameConverter() |
157 | | -{ |
158 | | -$this->expectException(LogicException::class); |
| 136 | +$data = [ |
| 137 | +'one' => [ |
| 138 | +'two' => [ |
| 139 | +'three' =>'foo', |
| 140 | +], |
| 141 | +'four' =>'bar', |
| 142 | + ], |
| 143 | +]; |
| 144 | +$test =$normalizer->denormalize( |
| 145 | +$data, |
| 146 | +NestedDummy::class, |
| 147 | +'any', |
| 148 | +['flatten_nested_attributes' =>true] |
| 149 | +); |
| 150 | +$this->assertEquals('foo',$test->foo); |
| 151 | +$this->assertEquals('bar',$test->bar); |
| 152 | +} |
| 153 | + |
| 154 | +publicfunctiontestNormalizeWithNestedAttributesAndNoMetadataNameConverter() |
| 155 | +{ |
| 156 | +$this->expectException(LogicException::class); |
159 | 157 | $this->expectExceptionMessage('A metadata aware name converter must be provided in the constructor when setting "flatten_nested_attributes" to true.'); |
160 | | -$foobar =newNestedDummy(); |
161 | | -$foobar->foo ='foo'; |
162 | | -$foobar->bar ='bar'; |
163 | | -$normalizer =newObjectNormalizer(); |
164 | | -$normalizer->normalize( |
165 | | -$foobar, |
166 | | -'any', |
167 | | -['flatten_nested_attributes' =>true] |
168 | | -); |
169 | | -} |
170 | | - |
171 | | -publicfunctiontestNormalizeWithNestedAttributesMixingArrayTypes() |
172 | | -{ |
173 | | -$this->expectException(LogicException::class); |
| 158 | +$foobar =newNestedDummy(); |
| 159 | +$foobar->foo ='foo'; |
| 160 | +$foobar->bar ='bar'; |
| 161 | +$normalizer =newObjectNormalizer(); |
| 162 | +$normalizer->normalize( |
| 163 | +$foobar, |
| 164 | +'any', |
| 165 | +['flatten_nested_attributes' =>true] |
| 166 | +); |
| 167 | +} |
| 168 | + |
| 169 | +publicfunctiontestNormalizeWithNestedAttributesMixingArrayTypes() |
| 170 | +{ |
| 171 | +$this->expectException(LogicException::class); |
174 | 172 | $this->expectExceptionMessage('The element you are trying to set is already populated: "two"'); |
175 | | -$foobar =newAlreadyPopulatedNestedDummy(); |
176 | | -$foobar->foo ='foo'; |
177 | | -$foobar->bar ='bar'; |
178 | | -$normalizer =newObjectNormalizer( |
179 | | -null, |
180 | | -newMetadataAwareNameConverter( |
181 | | -newClassMetadataFactory( |
182 | | -newAnnotationLoader( |
183 | | -newAnnotationReader() |
184 | | -) |
185 | | -) |
186 | | -) |
187 | | -); |
188 | | -$normalizer->normalize( |
189 | | -$foobar, |
190 | | -'any', |
191 | | -['flatten_nested_attributes' =>true] |
192 | | -); |
193 | | -} |
194 | | -
|
195 | | -publicfunctiontestNormalizeWithNestedAttributesElementAlreadySet() |
196 | | -{ |
197 | | -$this->expectException(LogicException::class); |
| 173 | +$foobar =newAlreadyPopulatedNestedDummy(); |
| 174 | +$foobar->foo ='foo'; |
| 175 | +$foobar->bar ='bar'; |
| 176 | +$normalizer =newObjectNormalizer( |
| 177 | +null, |
| 178 | +newMetadataAwareNameConverter( |
| 179 | +newClassMetadataFactory( |
| 180 | +newAnnotationLoader( |
| 181 | +newAnnotationReader() |
| 182 | +) |
| 183 | +) |
| 184 | +) |
| 185 | +); |
| 186 | +$normalizer->normalize( |
| 187 | +$foobar, |
| 188 | +'any', |
| 189 | +['flatten_nested_attributes' =>true] |
| 190 | +); |
| 191 | +} |
| 192 | + |
| 193 | +publicfunctiontestNormalizeWithNestedAttributesElementAlreadySet() |
| 194 | +{ |
| 195 | +$this->expectException(LogicException::class); |
198 | 196 | $this->expectExceptionMessage('The element you are trying to set is already populated: "three"'); |
199 | | -$foobar =newDuplicateNestedDummy(); |
200 | | -$foobar->foo ='foo'; |
201 | | -$foobar->bar ='bar'; |
202 | | -$normalizer =newObjectNormalizer( |
203 | | -null, |
204 | | -newMetadataAwareNameConverter( |
205 | | -newClassMetadataFactory( |
206 | | -newAnnotationLoader( |
207 | | -newAnnotationReader() |
208 | | -) |
209 | | -) |
210 | | -) |
211 | | -); |
212 | | -$normalizer->normalize( |
213 | | -$foobar, |
214 | | -'any', |
215 | | -['flatten_nested_attributes' =>true] |
216 | | -); |
217 | | -} |
218 | | - |
219 | | -publicfunctiontestNormalizeWithNestedAttributes() |
220 | | -{ |
221 | | -$foobar =newNestedDummy(); |
222 | | -$foobar->foo ='foo'; |
223 | | -$foobar->bar ='bar'; |
224 | | -$data = [ |
225 | | -'one' => [ |
226 | | -'two' => [ |
227 | | -'three' =>'foo' |
228 | | -], |
229 | | -'four' =>'bar' |
230 | | -] |
231 | | -]; |
232 | | -$normalizer =newObjectNormalizer( |
233 | | -null, |
234 | | -newMetadataAwareNameConverter( |
235 | | -newClassMetadataFactory( |
236 | | -newAnnotationLoader( |
237 | | -newAnnotationReader() |
238 | | -) |
239 | | -) |
240 | | -) |
241 | | -); |
242 | | -$test =$normalizer->normalize( |
243 | | -$foobar, |
244 | | -'any', |
245 | | -['flatten_nested_attributes' =>true] |
246 | | -); |
247 | | -$this->assertEquals($data,$test); |
248 | | -} |
| 197 | +$foobar =newDuplicateNestedDummy(); |
| 198 | +$foobar->foo ='foo'; |
| 199 | +$foobar->bar ='bar'; |
| 200 | +$normalizer =newObjectNormalizer( |
| 201 | +null, |
| 202 | +newMetadataAwareNameConverter( |
| 203 | +newClassMetadataFactory( |
| 204 | +newAnnotationLoader( |
| 205 | +newAnnotationReader() |
| 206 | +) |
| 207 | +) |
| 208 | +) |
| 209 | +); |
| 210 | +$normalizer->normalize( |
| 211 | +$foobar, |
| 212 | +'any', |
| 213 | +['flatten_nested_attributes' =>true] |
| 214 | +); |
| 215 | +} |
| 216 | + |
| 217 | +publicfunctiontestNormalizeWithNestedAttributes() |
| 218 | +{ |
| 219 | +$foobar =newNestedDummy(); |
| 220 | +$foobar->foo ='foo'; |
| 221 | +$foobar->bar ='bar'; |
| 222 | +$data = [ |
| 223 | +'one' => [ |
| 224 | +'two' => [ |
| 225 | +'three' =>'foo', |
| 226 | +], |
| 227 | +'four' =>'bar', |
| 228 | + ], |
| 229 | +]; |
| 230 | +$normalizer =newObjectNormalizer( |
| 231 | +null, |
| 232 | +newMetadataAwareNameConverter( |
| 233 | +newClassMetadataFactory( |
| 234 | +newAnnotationLoader( |
| 235 | +newAnnotationReader() |
| 236 | +) |
| 237 | +) |
| 238 | +) |
| 239 | +); |
| 240 | +$test =$normalizer->normalize( |
| 241 | +$foobar, |
| 242 | +'any', |
| 243 | +['flatten_nested_attributes' =>true] |
| 244 | +); |
| 245 | +$this->assertEquals($data,$test); |
| 246 | +} |
249 | 247 |
|
250 | 248 | publicfunctiontestDenormalizeCollectionDecodedFromXmlWithOneChild() |
251 | 249 | { |
@@ -574,42 +572,41 @@ class EmptyDummy |
574 | 572 |
|
575 | 573 | class AlreadyPopulatedNestedDummy |
576 | 574 | { |
577 | | -/** |
578 | | - * @SerializedName("one.two.three") |
579 | | - */ |
580 | | -public$foo; |
581 | | - |
582 | | -/** |
583 | | - * @SerializedName("one.two") |
584 | | - */ |
585 | | -public$bar; |
586 | | -} |
| 575 | +/** |
| 576 | + * @SerializedName("one.two.three") |
| 577 | + */ |
| 578 | +public$foo; |
587 | 579 |
|
| 580 | +/** |
| 581 | + * @SerializedName("one.two") |
| 582 | + */ |
| 583 | +public$bar; |
| 584 | +} |
588 | 585 |
|
589 | 586 | class DuplicateNestedDummy |
590 | 587 | { |
591 | | -/** |
592 | | - * @SerializedName("one.two.three") |
593 | | - */ |
594 | | -public$foo; |
595 | | - |
596 | | -/** |
597 | | - * @SerializedName("one.two.three") |
598 | | - */ |
599 | | -public$bar; |
| 588 | +/** |
| 589 | + * @SerializedName("one.two.three") |
| 590 | + */ |
| 591 | +public$foo; |
| 592 | + |
| 593 | +/** |
| 594 | + * @SerializedName("one.two.three") |
| 595 | + */ |
| 596 | +public$bar; |
600 | 597 | } |
601 | 598 |
|
602 | 599 | class NestedDummy |
603 | 600 | { |
604 | | -/** |
605 | | - * @SerializedName("one.two.three") |
606 | | - */ |
607 | | -public$foo; |
608 | | - |
609 | | -/** |
610 | | - * @SerializedName("one.four") |
611 | | - */ |
612 | | -public$bar; |
| 601 | +/** |
| 602 | + * @SerializedName("one.two.three") |
| 603 | + */ |
| 604 | +public$foo; |
| 605 | + |
| 606 | +/** |
| 607 | + * @SerializedName("one.four") |
| 608 | + */ |
| 609 | +public$bar; |
613 | 610 | } |
614 | 611 |
|
615 | 612 | class AbstractObjectNormalizerWithMetadataextends AbstractObjectNormalizer |
|