示例#1
0
 /**
  * Test Get/Set, create, endpoint methods.
  */
 public function testFollowEntity()
 {
     $follow = Follow::create();
     $this->assertInstanceOf('Shoko\\TwitchApiBundle\\Model\\Entity\\Follow', $follow);
     $date = new \DateTime();
     $this->assertEquals(null, $follow->getCreatedAt());
     $this->assertEquals($date, $follow->setCreatedAt($date)->getCreatedAt());
     $this->assertEquals(array(), $follow->getLinks());
     $link = 'some_link';
     $this->assertEquals([$link], $follow->setLinks([$link])->getLinks());
     $this->assertEquals(false, $follow->isNotifications());
     $this->assertEquals(true, $follow->setNotifications(true)->isNotifications());
     $this->assertEquals(null, $follow->getChannel());
     $channel = Channel::create();
     $this->assertEquals($channel, $follow->setChannel($channel)->getChannel());
 }
 /**
  * @param array $data
  * @param false|Follow $follow
  *
  * @return Follow
  */
 public function createEntity(array $data, $follow = false)
 {
     if (false === $follow) {
         $follow = Follow::create();
     }
     if (isset($data['notifications'])) {
         $follow = $follow->setNotifications($data['notifications']);
     }
     if (isset($data['created_at'])) {
         $follow = $follow->setCreatedAt(new \DateTime($data['created_at']));
     }
     if (isset($data['_links'])) {
         $follow = $follow->setLinks($data['_links']);
     }
     if (isset($data['channel'])) {
         $follow = $follow->setChannel((new ChannelFactory())->createEntity($data['channel']));
     }
     return $follow;
 }