/** * @param \stdClass $directMessage * @param array $context * @return TwitterDirectMessage */ public function unserialize($directMessage, array $context = []) { Assertion::true($this->canUnserialize($directMessage), 'object is not unserializable'); $dm = $directMessage->direct_message; $createdAt = new \DateTimeImmutable($dm->created_at); Assertion::eq(new \DateTimeZone('UTC'), $createdAt->getTimezone()); return TwitterDirectMessage::create(TwitterMessageId::create($dm->id), $this->userSerializer->unserialize($dm->sender), $this->userSerializer->unserialize($dm->recipient), $dm->text, $createdAt, $this->twitterEntitiesSerializer->canUnserialize($dm->entities) ? $this->twitterEntitiesSerializer->unserialize($dm->entities) : TwitterEntities::create()); }
/** * @test */ public function itShouldBuildTheObjectWithEntities() { $this->messageContainsHashtag(); $this->messageContainsUserMention(); $tweet = TwitterDirectMessage::create($this->id, $this->sender, $this->recipient, $this->complexText, $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)); }
public function setUp() { $faker = Factory::create(); $this->id = $faker->randomNumber(); $this->text = $faker->text(); $this->date = new \DateTimeImmutable('now', new \DateTimeZone('UTC')); $this->serializedSender = new \stdClass(); $this->serializedRecipient = new \stdClass(); $this->serializedEntities = new \stdClass(); $this->sender = \Mockery::mock(TwitterUser::class); $this->recipient = \Mockery::mock(TwitterUser::class); $this->twitterEntities = \Mockery::mock(TwitterEntities::class); $this->serializedDirectMessage = $this->getSerializedDirectMessage(); $this->directMessage = TwitterDirectMessage::create(TwitterMessageId::create($this->id), $this->sender, $this->recipient, $this->text, $this->date, $this->twitterEntities); $this->userSerializer = \Mockery::mock(TwitterUserSerializer::class); $this->entitiesSerializer = \Mockery::mock(TwitterEntitiesSerializer::class); $this->serviceUnderTest = new TwitterDirectMessageSerializer($this->userSerializer, $this->entitiesSerializer); }