@@ -181,6 +181,79 @@ private function getDenormalizerForStringCollection()
181
181
return $ denormalizer ;
182
182
}
183
183
184
+ public function testDenormalizeBasicTypePropertiesFromXml ()
185
+ {
186
+ $ denormalizer = $ this ->getDenormalizerForObjectWithBasicProperties ();
187
+
188
+ // bool
189
+ $ objectWithBooleanProperties = $ denormalizer ->denormalize (
190
+ [
191
+ 'boolTrue1 ' => 'true ' ,
192
+ 'boolFalse1 ' => 'false ' ,
193
+ 'boolTrue2 ' => '1 ' ,
194
+ 'boolFalse2 ' => '0 ' ,
195
+ 'int1 ' => '4711 ' ,
196
+ 'int2 ' => '-4711 ' ,
197
+ 'float1 ' => '123.456 ' ,
198
+ 'float2 ' => '-1.2344e56 ' ,
199
+ 'float3 ' => '45E-6 ' ,
200
+ 'floatNaN ' => 'NaN ' ,
201
+ 'floatInf ' => 'INF ' ,
202
+ 'floatNegInf ' => '-INF ' ,
203
+ ],
204
+ ObjectWithBasicProperties::class,
205
+ 'xml '
206
+ );
207
+
208
+ $ this ->assertInstanceOf (ObjectWithBasicProperties::class, $ objectWithBooleanProperties );
209
+
210
+ // Bool Properties
211
+ $ this ->assertTrue ($ objectWithBooleanProperties ->boolTrue1 );
212
+ $ this ->assertFalse ($ objectWithBooleanProperties ->boolFalse1 );
213
+ $ this ->assertTrue ($ objectWithBooleanProperties ->boolTrue2 );
214
+ $ this ->assertFalse ($ objectWithBooleanProperties ->boolFalse2 );
215
+
216
+ // Integer Properties
217
+ $ this ->assertEquals (4711 , $ objectWithBooleanProperties ->int1 );
218
+ $ this ->assertEquals (-4711 , $ objectWithBooleanProperties ->int2 );
219
+
220
+ // Float Properties
221
+ $ this ->assertEqualsWithDelta (123.456 , $ objectWithBooleanProperties ->float1 , 0.01 );
222
+ $ this ->assertEqualsWithDelta (-1.2344e56 , $ objectWithBooleanProperties ->float2 , 1 );
223
+ $ this ->assertEqualsWithDelta (45E-6 , $ objectWithBooleanProperties ->float3 , 1 );
224
+ $ this ->assertNan ($ objectWithBooleanProperties ->floatNaN );
225
+ $ this ->assertInfinite ($ objectWithBooleanProperties ->floatInf );
226
+ $ this ->assertEquals (-INF , $ objectWithBooleanProperties ->floatNegInf );
227
+ }
228
+
229
+ private function getDenormalizerForObjectWithBasicProperties ()
230
+ {
231
+ $ extractor = $ this ->getMockBuilder (PhpDocExtractor::class)->getMock ();
232
+ $ extractor ->method ('getTypes ' )
233
+ ->will ($ this ->onConsecutiveCalls (
234
+ [new Type ('bool ' )],
235
+ [new Type ('bool ' )],
236
+ [new Type ('bool ' )],
237
+ [new Type ('bool ' )],
238
+ [new Type ('int ' )],
239
+ [new Type ('int ' )],
240
+ [new Type ('float ' )],
241
+ [new Type ('float ' )],
242
+ [new Type ('float ' )],
243
+ [new Type ('float ' )],
244
+ [new Type ('float ' )],
245
+ [new Type ('float ' )]
246
+ ));
247
+
248
+ $ denormalizer = new AbstractObjectNormalizerCollectionDummy (null , null , $ extractor );
249
+ $ arrayDenormalizer = new ArrayDenormalizerDummy ();
250
+ $ serializer = new SerializerCollectionDummy ([$ arrayDenormalizer , $ denormalizer ]);
251
+ $ arrayDenormalizer ->setSerializer ($ serializer );
252
+ $ denormalizer ->setSerializer ($ serializer );
253
+
254
+ return $ denormalizer ;
255
+ }
256
+
184
257
/**
185
258
* Test that additional attributes throw an exception if no metadata factory is specified.
186
259
*/
@@ -250,6 +323,45 @@ protected function setAttributeValue($object, $attribute, $value, $format = null
250
323
}
251
324
}
252
325
326
+ class ObjectWithBasicProperties
327
+ {
328
+ /** @var bool */
329
+ public $ boolTrue1 ;
330
+
331
+ /** @var bool */
332
+ public $ boolFalse1 ;
333
+
334
+ /** @var bool */
335
+ public $ boolTrue2 ;
336
+
337
+ /** @var bool */
338
+ public $ boolFalse2 ;
339
+
340
+ /** @var int */
341
+ public $ int1 ;
342
+
343
+ /** @var int */
344
+ public $ int2 ;
345
+
346
+ /** @var float */
347
+ public $ float1 ;
348
+
349
+ /** @var float */
350
+ public $ float2 ;
351
+
352
+ /** @var float */
353
+ public $ float3 ;
354
+
355
+ /** @var float */
356
+ public $ floatNaN ;
357
+
358
+ /** @var float */
359
+ public $ floatInf ;
360
+
361
+ /** @var float */
362
+ public $ floatNegInf ;
363
+ }
364
+
253
365
class StringCollection
254
366
{
255
367
/** @var string[] */
0 commit comments