public function testObjectToPopulate() { $dummy = new GetSetDummy(); $dummy->setFoo('foo'); $obj = $this->normalizer->denormalize(array('bar' => 'bar'), __NAMESPACE__ . '\\GetSetDummy', null, array('object_to_populate' => $dummy)); $this->assertEquals($dummy, $obj); $this->assertEquals('foo', $obj->getFoo()); $this->assertEquals('bar', $obj->getBar()); }
public function testConstructorWithObjectDenormalize() { $data = new \stdClass(); $data->foo = 'foo'; $data->bar = 'bar'; $data->fooBar = 'foobar'; $obj = $this->normalizer->denormalize($data, __NAMESPACE__ . '\\GetConstructorDummy', 'any'); $this->assertEquals('foo', $obj->getFoo()); $this->assertEquals('bar', $obj->getBar()); }
public function testPrivateSetter() { $obj = $this->normalizer->denormalize(array('foo' => 'foobar'), __NAMESPACE__ . '\\ObjectWithPrivateSetterDummy'); $this->assertEquals('bar', $obj->getFoo()); }
public function testDenormalizeNonExistingAttribute() { $this->assertEquals(new PropertyDummy(), $this->normalizer->denormalize(array('non_existing' => true), __NAMESPACE__ . '\\PropertyDummy')); }
/** * The raw response from the api must be mapped to a correctly typed object. * This method does the job flattening the result and by using a GetSetMethodNormalizer. * What does that mean? This means that if your response has a key $entry['id_str'] the * setter setIdStr($entry['id_str']) is used. If the response has a key * $entry['media'][0]['media_url'] the setter setMedia0MediaUrl(..) is used. Therefore * you can persist whatever information you want to persist from the direct response * by using the correct name for the entity-field (and then also for the setter). * * @param object $object the json decoded object response by the api * @param array $dateFields fields that should be formatted as datetime object * @return YoutubeEntityInterface */ protected function deserializeRawObject($object, $dateFields = array()) { // flatten object $object = self::flatten($object); foreach ($dateFields as $df) { if (array_key_exists($df, $object)) { $object[$df] = new \DateTime($object[$df]); } } $normalizer = new GetSetMethodNormalizer(); $normalizer->setCamelizedAttributes(array_keys($object)); return $normalizer->denormalize($object, $this->socialEntityClass); }