public function testNormalization()
 {
     $object = new A();
     $object->setRid(2)->setName('testName')->setStatus(true)->setHiddenStatus(false);
     $result = $this->unitUnderTest->normalize($object);
     $this->assertCount(3, $result);
     $this->assertArrayHasKey('id', $result);
     $this->assertArrayHasKey('name', $result);
     $this->assertArrayHasKey('status', $result);
     $this->assertEquals(2, $result['id']);
     $this->assertEquals('testName', $result['name']);
     $this->assertTrue($result['status']);
     $object = new AChildren();
     $object->setRid(3)->setName('children')->setStatus(false)->setHiddenStatus(true);
     $object->setFloat(3.23)->setArray(array(3, 2, null))->setAssocArray(array('true' => 345, 'false' => 34));
     $time = time();
     $object->setDateTime(new DateTime(date('Y-m-d H:i:s', $time)));
     $object->setNull(null);
     $result = $this->unitUnderTest->normalize($object);
     $this->assertCount(8, $result);
     $this->assertArrayHasKey('id', $result);
     $this->assertArrayHasKey('name', $result);
     $this->assertArrayHasKey('status', $result);
     $this->assertArrayHasKey('float', $result);
     $this->assertArrayHasKey('null', $result);
     $this->assertArrayHasKey('dateTime', $result);
     $this->assertArrayHasKey('array', $result);
     $this->assertArrayHasKey('assocArray', $result);
     $this->assertEquals(3, $result['id']);
     $this->assertEquals('children', $result['name']);
     $this->assertFalse($result['status']);
     $this->assertNull($result['null']);
     $this->assertEquals(3.23, $result['float']);
     $testTime = new DateTime(date('Y-m-d H:i:s', $time));
     $this->assertEquals($testTime->format(DateTime::ISO8601), $result['dateTime']);
     $this->assertEquals(array(3, 2, null), $result['array']);
     $this->assertEquals(array('true' => 345, 'false' => 34), $result['assocArray']);
     $objectComplex = new E();
     $objectComplex->setRid(434);
     $objectComplex->setObject($object);
     $objectComplex->setArrayOfObjects(array($object, $object));
     $resultComplex = $this->unitUnderTest->normalize($objectComplex);
     $this->assertCount(3, $resultComplex);
     $this->assertArrayHasKey('object', $resultComplex);
     $this->assertEquals($result, $resultComplex['object']);
     $this->assertArrayHasKey('arrayOfObjects', $resultComplex);
     $this->assertEquals(array($result, $result), $resultComplex['arrayOfObjects']);
 }
Beispiel #2
0
 /**
  * @return array
  */
 public function childrenDataProvider()
 {
     $time = time();
     $testTime = new DateTime(date('Y-m-d H:i:s', $time));
     $aChildren = new AChildren();
     $aChildren->setRid(1);
     $aChildren->setStatus(true);
     $aChildren->setFloat(3.23);
     $aChildren->setArray(array(3, null));
     $aChildren->setAssocArray(array('tr' => 2));
     $aChildren->setDateTime($testTime);
     $aChildren->setNull(null);
     $aChildren->setName('name');
     $aChildrenAsArray = array('id' => 1, 'name' => 'name', 'status' => true, 'float' => 3.23, 'dateTime' => $testTime->format(DateTime::ISO8601), 'null' => null, 'array' => array(3, null), 'assocArray' => array('tr' => 2));
     return array(array($aChildren, $aChildrenAsArray));
 }
 public function testExpose()
 {
     $time = time();
     $testTime = new DateTime(date('Y-m-d H:i:s', $time));
     $aChildren = new AChildren();
     $aChildren->setRid(1);
     $aChildren->setStatus(true);
     $aChildren->setFloat(3.23);
     $aChildren->setArray(array(3, null));
     $aChildren->setAssocArray(array('tr' => 2));
     $aChildren->setDateTime($testTime);
     $aChildren->setNull(null);
     $aChildren->setName('name');
     $property = new PropertyMetadata('name');
     $name = ObjectHelper::expose($aChildren, $property);
     $this->assertEquals('name', $name);
     $stdClass = new \stdClass();
     $stdClass->someProperty = 'someProperty';
     $someProperty = ObjectHelper::expose($stdClass, new PropertyMetadata('someProperty'));
     $this->assertEquals('someProperty', $someProperty);
 }
 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);
 }