/** * @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 itShouldBuildTheObjectWithEntities() { $this->messageContainsHashtag(); $this->messageContainsUserMention(); $tweet = Tweet::create($this->id, $this->sender, $this->complexText, $this->lang, $this->date, $this->entities); $this->assertEquals(array('#' . $this->hashtagText), $tweet->getFormattedHashtags()); $this->assertEquals(array('@' . $this->userName), $tweet->getFormattedUserMentions()); $this->assertEquals($this->text, $tweet->getStrippedText()); $this->assertTrue($tweet->containsHashtag($this->hashtagText)); $this->assertFalse($tweet->containsHashtag($this->faker->word)); }