/**
  * @dataProvider childrenDataProvider
  * @param AChildren $aChildren
  * @param array $aChildrenAsArray
  */
 public function testNormalize($aChildren, $aChildrenAsArray)
 {
     $object = new E();
     $object->setRid(3);
     $object->setObject($aChildren);
     $object->setArrayOfObjects(array($aChildren));
     $className = ObjectHelper::getFullClassName($object);
     $metadata = $this->metadataFactory->getMetadataForClass($className);
     $properties = $metadata->getProperties();
     $arrayOfObjectsProperty = $properties['arrayOfObjects'];
     $data = ObjectHelper::expose($object, $arrayOfObjectsProperty);
     $normalizedArray = $this->arrayTransformer->normalize($data, $arrayOfObjectsProperty);
     $this->assertEquals(array($aChildrenAsArray), $normalizedArray);
 }
 /**
  * @group Test
  */
 public function testDenormalizationWithData()
 {
     $object = new E();
     $objectA = new AChildren();
     $objectA->setRid(11);
     $objectA->setName(23);
     $objectA->setFloat(2.3);
     $objectA->setHiddenStatus(true);
     $object->setRid(2);
     $object->setObject($objectA);
     $object->setArrayOfObjects(array($objectA));
     $array = array('rid' => 23, 'object' => array('id' => 3, 'float' => null), 'arrayOfObjects' => array(array('id' => 3, 'float' => null)));
     $result = $this->unitUnderTest->denormalize($array, $object);
     $this->assertInstanceOf('Opensoft\\SimpleSerializer\\Tests\\Metadata\\Driver\\Fixture\\A\\E', $result);
     $this->assertInstanceOf('Opensoft\\SimpleSerializer\\Tests\\Metadata\\Driver\\Fixture\\A\\AChildren', $result->getObject());
     $objects = $result->getArrayOfObjects();
     $this->assertCount(1, $objects);
     $this->assertInstanceOf('Opensoft\\SimpleSerializer\\Tests\\Metadata\\Driver\\Fixture\\A\\AChildren', $objects[0]);
     $this->assertEquals(23, $result->getRid());
     $this->assertEquals(3, $result->getObject()->getRid());
     $this->assertEquals(23, $result->getObject()->getName());
     $this->assertNull($result->getObject()->getFloat());
     $this->assertTrue($result->getObject()->getHiddenStatus());
     $this->assertEquals(3, $objects[0]->getRid());
     $this->assertEquals(23, $objects[0]->getName());
     $this->assertNull($objects[0]->getFloat());
     $this->assertTrue($objects[0]->getHiddenStatus());
 }
Exemplo n.º 3
0
 public function testArraySerialize()
 {
     $time = time();
     $testTime = new DateTime(date('Y-m-d H:i:s', $time));
     $aChildren = new AChildren();
     $aChildren->setRid(1);
     $aChildren->setStatus(true);
     $aChildren->setHiddenStatus(true);
     $aChildren->setFloat(3.23);
     $aChildren->setArray(array(3, null));
     $aChildren->setAssocArray(array('tr' => 2));
     $aChildren->setDateTime($testTime);
     $aChildren->setNull(null);
     $aChildren->setName('name');
     $e = new E();
     $e->setRid(3);
     $e->setObject($aChildren);
     $e->setArrayOfObjects(array($aChildren));
     $result = $this->unitUnderTest->serialize(array($e));
     $expectedString = '[{"rid":3,"object":{"id":1,"name":"name","status":true,"float":3.23,"dateTime":"' . $testTime->format(DateTime::ISO8601) . '","null":null,"array":[3,null],"assocArray":{"tr":2}},"arrayOfObjects":[{"id":1,"name":"name","status":true,"float":3.23,"dateTime":"' . $testTime->format(DateTime::ISO8601) . '","null":null,"array":[3,null],"assocArray":{"tr":2}}]}]';
     $this->assertEquals($expectedString, $result);
 }