コード例 #1
0
 /**
  * @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());
 }
コード例 #2
0
 /**
  * @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));
 }
コード例 #3
0
 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);
 }