2626
2727class AbstractObjectNormalizerTest extends TestCase
2828{
29- public function testDenormalize ()
29+ public function _testDenormalize ()
3030 {
3131 $ normalizer = new AbstractObjectNormalizerDummy ();
3232 $ normalizedData = $ normalizer ->denormalize (['foo ' => 'foo ' , 'bar ' => 'bar ' , 'baz ' => 'baz ' ], __NAMESPACE__ .'\Dummy ' );
@@ -36,7 +36,7 @@ public function testDenormalize()
3636 $ this ->assertSame ('baz ' , $ normalizedData ->baz );
3737 }
3838
39- public function testInstantiateObjectDenormalizer ()
39+ public function _testInstantiateObjectDenormalizer ()
4040 {
4141 $ data = ['foo ' => 'foo ' , 'bar ' => 'bar ' , 'baz ' => 'baz ' ];
4242 $ class = __NAMESPACE__ .'\Dummy ' ;
@@ -47,7 +47,7 @@ public function testInstantiateObjectDenormalizer()
4747 $ this ->assertInstanceOf (__NAMESPACE__ .'\Dummy ' , $ normalizer ->instantiateObject ($ data , $ class , $ context , new \ReflectionClass ($ class ), []));
4848 }
4949
50- public function testDenormalizeWithExtraAttributes ()
50+ public function _testDenormalizeWithExtraAttributes ()
5151 {
5252 $ this ->expectException ('Symfony\Component\Serializer\Exception\ExtraAttributesException ' );
5353 $ this ->expectExceptionMessage ('Extra attributes are not allowed ("fooFoo", "fooBar" are unknown). ' );
@@ -61,7 +61,7 @@ public function testDenormalizeWithExtraAttributes()
6161 );
6262 }
6363
64- public function testDenormalizeWithExtraAttributesAndNoGroupsWithMetadataFactory ()
64+ public function _testDenormalizeWithExtraAttributesAndNoGroupsWithMetadataFactory ()
6565 {
6666 $ this ->expectException ('Symfony\Component\Serializer\Exception\ExtraAttributesException ' );
6767 $ this ->expectExceptionMessage ('Extra attributes are not allowed ("fooFoo", "fooBar" are unknown). ' );
@@ -74,7 +74,7 @@ public function testDenormalizeWithExtraAttributesAndNoGroupsWithMetadataFactory
7474 );
7575 }
7676
77- public function testDenormalizeCollectionDecodedFromXmlWithOneChild ()
77+ public function _testDenormalizeCollectionDecodedFromXmlWithOneChild ()
7878 {
7979 $ denormalizer = $ this ->getDenormalizerForDummyCollection ();
8080
@@ -94,7 +94,7 @@ public function testDenormalizeCollectionDecodedFromXmlWithOneChild()
9494 $ this ->assertInstanceOf (DummyChild::class, $ dummyCollection ->children [0 ]);
9595 }
9696
97- public function testDenormalizeCollectionDecodedFromXmlWithTwoChildren ()
97+ public function _testDenormalizeCollectionDecodedFromXmlWithTwoChildren ()
9898 {
9999 $ denormalizer = $ this ->getDenormalizerForDummyCollection ();
100100
@@ -134,7 +134,7 @@ private function getDenormalizerForDummyCollection()
134134 return $ denormalizer ;
135135 }
136136
137- public function testDenormalizeStringCollectionDecodedFromXmlWithOneChild ()
137+ public function _testDenormalizeStringCollectionDecodedFromXmlWithOneChild ()
138138 {
139139 $ denormalizer = $ this ->getDenormalizerForStringCollection ();
140140
@@ -148,7 +148,7 @@ public function testDenormalizeStringCollectionDecodedFromXmlWithOneChild()
148148 $ this ->assertEquals ('foo ' , $ stringCollection ->children [0 ]);
149149 }
150150
151- public function testDenormalizeStringCollectionDecodedFromXmlWithTwoChildren ()
151+ public function _testDenormalizeStringCollectionDecodedFromXmlWithTwoChildren ()
152152 {
153153 $ denormalizer = $ this ->getDenormalizerForStringCollection ();
154154
@@ -181,10 +181,83 @@ private function getDenormalizerForStringCollection()
181181 return $ denormalizer ;
182182 }
183183
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+
184257 /**
185258 * Test that additional attributes throw an exception if no metadata factory is specified.
186259 */
187- public function testExtraAttributesException ()
260+ public function _testExtraAttributesException ()
188261 {
189262 $ this ->expectException ('Symfony\Component\Serializer\Exception\LogicException ' );
190263 $ this ->expectExceptionMessage ('A class metadata factory must be provided in the constructor when setting "allow_extra_attributes" to false. ' );
@@ -250,6 +323,45 @@ protected function setAttributeValue($object, $attribute, $value, $format = null
250323 }
251324}
252325
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+
253365class StringCollection
254366{
255367 /** @var string[] */
0 commit comments