/** * @param \stdClass $obj * @param array $context * @return \Twitter\Object\Tweet */ public function unserialize($obj, array $context = []) { Assertion::true($this->canUnserialize($obj), 'object is not unserializable'); $createdAt = new \DateTimeImmutable($obj->created_at); Assertion::eq(new \DateTimeZone('UTC'), $createdAt->getTimezone()); return Tweet::create(TwitterMessageId::create($obj->id), $this->userSerializer->unserialize($obj->user), $obj->text, $obj->lang, $createdAt, $obj->entities ? $this->twitterEntitiesSerializer->unserialize($obj->entities) : TwitterEntities::create(), $obj->coordinates ? $this->coordinatesSerializer->unserialize($obj->coordinates) : null, $obj->place ? $this->placeSerializer->unserialize($obj->place) : null, $obj->in_reply_to_status_id, $obj->in_reply_to_user_id, $obj->in_reply_to_screen_name, $obj->retweeted, $obj->retweet_count, $obj->favorited, $obj->favorite_count, $obj->truncated, $obj->source, isset($obj->retweeted_status) ? $this->unserialize($obj->retweeted_status) : null); }
/** * @test */ public function itShouldUnserialize() { $coordinates = $this->serviceUnderTest->unserialize($this->buildSerializedCoordinates()); $this->assertEquals($this->longitude, $coordinates->getLongitude()); $this->assertEquals($this->latitude, $coordinates->getLatitude()); $this->assertEquals($this->type, $coordinates->getType()); }