Example #1
0
 /**
  * Test Get/Set, create, endpoint methods.
  */
 public function testStreamEntity()
 {
     $stream = Stream::create();
     $this->assertInstanceOf('Shoko\\TwitchApiBundle\\Model\\Entity\\Stream', $stream);
     $this->assertEquals(null, $stream->getGame());
     $this->assertEquals('some_game', $stream->setGame('some_game')->getGame());
     $date = new \DateTime();
     $this->assertEquals(null, $stream->getCreatedAt());
     $this->assertEquals($date, $stream->setCreatedAt($date)->getCreatedAt());
     $this->assertEquals(array(), $stream->getLinks());
     $link = 'some_link';
     $this->assertEquals([$link], $stream->setLinks([$link])->getLinks());
     $this->assertEquals(array(), $stream->getPreview());
     $preview = 'some_preview';
     $this->assertEquals([$preview], $stream->setPreview([$preview])->getPreview());
     $this->assertEquals(null, $stream->getId());
     $this->assertEquals('some_id', $stream->setId('some_id')->getId());
     $this->assertEquals(false, $stream->isPlaylist());
     $this->assertEquals(true, $stream->setPlaylist(true)->isPlaylist());
     $this->assertEquals(null, $stream->getDelay());
     $this->assertEquals('some_delay', $stream->setDelay('some_delay')->getDelay());
     $this->assertEquals(0, $stream->getViewers());
     $this->assertEquals(42, $stream->setViewers(42)->getViewers());
     $this->assertEquals(0, $stream->getVideoHeight());
     $this->assertEquals(1080, $stream->setVideoHeight(1080)->getVideoHeight());
     $this->assertEquals(0, $stream->getAverageFps());
     $this->assertEquals(42.42, $stream->setAverageFps(42.42)->getAverageFps());
     $this->assertEquals(null, $stream->getChannel());
     $channel = Channel::create();
     $this->assertEquals($channel, $stream->setChannel($channel)->getChannel());
 }
 /**
  * @param array $data
  * @param false|Stream $stream
  *
  * @return Stream
  */
 public function createEntity(array $data, $stream = false)
 {
     if (false === $stream) {
         $stream = Stream::create();
     }
     if (isset($data['is_playlist'])) {
         $stream = $stream->setPlaylist($data['is_playlist']);
     }
     if (isset($data['game'])) {
         $stream = $stream->setGame($data['game']);
     }
     if (isset($data['delay'])) {
         $stream = $stream->setDelay($data['delay']);
     }
     if (isset($data['viewers'])) {
         $stream = $stream->setViewers($data['viewers']);
     }
     if (isset($data['created_at'])) {
         $stream = $stream->setCreatedAt(new \DateTime($data['created_at']));
     }
     if (isset($data['_links'])) {
         $stream = $stream->setLinks($data['_links']);
     }
     if (isset($data['_id'])) {
         $stream = $stream->setId($data['_id']);
     }
     if (isset($data['average_fps'])) {
         $stream = $stream->setAverageFps($data['average_fps']);
     }
     if (isset($data['video_height'])) {
         $stream = $stream->setVideoHeight($data['video_height']);
     }
     if (isset($data['channel'])) {
         $stream = $stream->setChannel((new ChannelFactory())->createEntity($data['channel']));
     }
     if (isset($data['preview'])) {
         $stream = $stream->setPreview($data['preview']);
     }
     return $stream;
 }