/**
  * @dataProvider attributeProvider
  */
 public function testFormatAttribute($attribute, $camelizedAttributes, $result)
 {
     $r = new \ReflectionObject($this->normalizer);
     $m = $r->getMethod('formatAttribute');
     $m->setAccessible(true);
     $this->normalizer->setCamelizedAttributes($camelizedAttributes);
     $this->assertEquals($m->invoke($this->normalizer, $attribute, $camelizedAttributes), $result);
 }
 /**
  * @group legacy
  */
 public function testLegacyCamelizedAttributesDenormalize()
 {
     $obj = new GetCamelizedDummy('dunglas.fr');
     $obj->setFooBar('les-tilleuls.coop');
     $obj->setBar_foo('lostinthesupermarket.fr');
     $this->normalizer->setCamelizedAttributes(array('kevin_dunglas'));
     $this->assertEquals($this->normalizer->denormalize(array('kevin_dunglas' => 'dunglas.fr', 'fooBar' => 'les-tilleuls.coop', 'bar_foo' => 'lostinthesupermarket.fr'), __NAMESPACE__ . '\\GetCamelizedDummy'), $obj);
     $this->normalizer->setCamelizedAttributes(array('foo_bar'));
     $this->assertEquals($this->normalizer->denormalize(array('kevinDunglas' => 'dunglas.fr', 'foo_bar' => 'les-tilleuls.coop', 'bar_foo' => 'lostinthesupermarket.fr'), __NAMESPACE__ . '\\GetCamelizedDummy'), $obj);
 }
Exemplo n.º 3
0
 /**
  * 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);
 }
 private function getMessages($fileName, $numberOfLines)
 {
     $normalizer = new GetSetMethodNormalizer();
     $encoder = new JsonEncoder();
     $serializer = new Serializer(array($normalizer), array($encoder));
     $normalizer->setCamelizedAttributes(array('level_name'));
     $messages = [];
     $file = array_reverse(file($fileName));
     foreach ($file as $line) {
         $messages[] = $serializer->deserialize($line, 'Sopinet\\Bundle\\LogBundle\\Entities\\Message', 'json');
         if (count($messages) == $numberOfLines) {
             break;
         }
     }
     return $messages;
 }