Example #1
0
 /**
  * @param  TwitterSerializable $object
  * @return \stdClass
  */
 public function serialize(TwitterSerializable $object)
 {
     /* @var Tweet $object */
     Assertion::true($this->canSerialize($object), 'object must be an instance of Tweet');
     Assertion::eq(new \DateTimeZone('UTC'), $object->getDate()->getTimezone());
     $tweet = new \stdClass();
     $tweet->id = (string) $object->getId();
     $tweet->user = $this->userSerializer->serialize($object->getSender());
     $tweet->text = $object->getText();
     $tweet->lang = $object->getLang();
     $tweet->created_at = $object->getDate()->format(TwitterDate::FORMAT);
     $tweet->entities = $this->twitterEntitiesSerializer->serialize($object->getEntities());
     $tweet->coordinates = $object->getCoordinates() ? $this->coordinatesSerializer->serialize($object->getCoordinates()) : null;
     $tweet->place = $object->getPlace() ? $this->placeSerializer->serialize($object->getPlace()) : null;
     $tweet->in_reply_to_status_id = $object->getInReplyToStatusId();
     $tweet->in_reply_to_user_id = $object->getInReplyToUserId();
     $tweet->in_reply_to_screen_name = $object->getInReplyToScreenName();
     $tweet->retweeted = $object->isRetweeted();
     $tweet->retweet_count = $object->getRetweetCount();
     $tweet->favorited = $object->isFavorited();
     $tweet->favorite_count = $object->getFavoriteCount();
     $tweet->truncated = $object->isTruncated();
     $tweet->source = $object->getSource();
     if ($object->getRetweetedStatus()) {
         $tweet->retweeted_status = $this->serialize($object->getRetweetedStatus());
     }
     return $tweet;
 }
Example #2
0
 /**
  * @test
  */
 public function itShouldSerializeWithLegalObject()
 {
     $serialized = $this->serializer->serialize($this->getValidObject());
     $this->assertEquals(new \stdClass(), $serialized);
 }