/** * @param array $data * * @return Tv */ public function create(array $data = array()) { if (!$data) { return null; } $tvShow = new Tv(); if (array_key_exists('credits', $data)) { if (array_key_exists('cast', $data['credits'])) { $tvShow->getCredits()->setCast($this->getCastFactory()->createCollection($data['credits']['cast'], new CastMember())); } if (array_key_exists('crew', $data['credits'])) { $tvShow->getCredits()->setCrew($this->getCrewFactory()->createCollection($data['credits']['crew'], new CrewMember())); } } /** External ids */ if (array_key_exists('external_ids', $data)) { $tvShow->setExternalIds($this->hydrate(new ExternalIds(), $data['external_ids'])); } /** Genres */ if (array_key_exists('genres', $data)) { $tvShow->setGenres($this->getGenreFactory()->createCollection($data['genres'])); } /** Images */ if (array_key_exists('images', $data)) { $tvShow->setImages($this->getImageFactory()->createCollectionFromTv($data['images'])); } if (array_key_exists('backdrop_path', $data)) { $tvShow->setBackdropImage($this->getImageFactory()->createFromPath($data['backdrop_path'], 'backdrop_path')); } if (array_key_exists('poster_path', $data)) { $tvShow->setPosterImage($this->getImageFactory()->createFromPath($data['poster_path'], 'poster_path')); } /** Translations */ if (array_key_exists('translations', $data) && null !== $data['translations']) { if (array_key_exists('translations', $data['translations'])) { $translations = $data['translations']['translations']; } else { $translations = $data['translations']; } $tvShow->setTranslations($this->createGenericCollection($translations, new Translation())); } /** Seasons */ if (array_key_exists('seasons', $data)) { $tvShow->setSeasons($this->getTvSeasonFactory()->createCollection($data['seasons'])); } /** Networks */ if (array_key_exists('networks', $data)) { $tvShow->setNetworks($this->getNetworkFactory()->createCollection($data['networks'])); } if (array_key_exists('videos', $data)) { $tvShow->setVideos($this->getVideoFactory()->createCollection($data['videos'])); } return $this->hydrate($tvShow, $data); }
/** * @param FixtureEpisodeData $fixture * @param Tv|null $result * * @return null|\Tmdb\Model\AbstractModel|Tv\Episode */ public function resolveSingle(FixtureEpisodeData $fixture, Tv $result = null) { if ($result === null) { return null; } $item = null; try { $repo = $this->getSingleRepository(); $item = $repo->load($result->getId(), $fixture->getSeasonNumber(), $fixture->getEpisodeNumberStart()); } catch (\Exception $e) { } return $item instanceof Tv\Episode ? $item : null; }
/** * @test * @todo see comments */ public function shouldBeFunctional() { $this->setUp(); $this->assertEquals('/sIJyCJedGlZf1TId41gCtkblBGo.jpg', $this->tv->getBackdropPath()); // created by $this->assertEquals(2, count($this->tv->getEpisodeRunTime())); $this->assertEquals(new \DateTime('2008-01-19'), $this->tv->getFirstAirDate()); // genres $this->assertEquals('http://www.amctv.com/shows/breaking-bad', $this->tv->getHomepage()); $this->assertEquals(1396, $this->tv->getId()); $this->assertEquals(false, $this->tv->getInProduction()); // languages $this->assertEquals(new \DateTime('2013-09-29'), $this->tv->getLastAirDate()); $this->assertEquals('Breaking Bad', $this->tv->getName()); // networks $this->assertEquals(62, $this->tv->getNumberOfEpisodes()); $this->assertEquals(5, $this->tv->getNumberOfSeasons()); $this->assertEquals('Breaking Bad', $this->tv->getOriginalName()); // origin_country $this->assertEquals('external', $this->tv->getOverview()); $this->assertEquals(8.14745667435, $this->tv->getPopularity()); $this->assertEquals('/iRDNn9EHKuBhGa77UBteazvsZa1.jpg', $this->tv->getPosterPath()); // seasons $this->assertEquals('Ended', $this->tv->getStatus()); $this->assertEquals(8.9, $this->tv->getVoteAverage()); $this->assertEquals(37, $this->tv->getVoteCount()); // credits // external_ids // images // translations }
/** * @expectedException Tmdb\Exception\RuntimeException * @test */ public function shouldThrowExceptionWhenConditionsNotMet() { $repository = $this->getRepositoryWithMockedHttpClient(); $tv = new Tv(); $tv->setId(self::TV_ID); $season = new Season(); $season->setId(self::SEASON_ID); $repository->load($tv, $season, null); }
/** * @param FixtureEpisodeData $f * @param Tv\Episode $e * @param Tv $s */ private function writeLookupSuccessEpisode(FixtureEpisodeData $f, Tv\Episode $e, Tv $s) { try { $fileSize = $f->getFile()->getSizeHuman(); } catch (\RuntimeException $e) { $fileSize = 'UNKNOWN'; $this->io()->warning(sprintf('An error occured while retrieving the file size for %s', $f->getFile()->getPathname())); } $country = ''; $countrySet = $s->getOriginCountry(); if ($countrySet->count() > 0) { $countryKey = $countrySet->getKeys()[0]; $country = $countrySet->get($countryKey)->getIso31661(); } $rows = [['Tvdb Id', $s->getId() . '/' . $e->getId()], ['File Path', $f->getFile()->getPathname()], ['Show Name', $s->getName()], ['Season', $e->getSeasonNumber()], ['Episode Number', $e->getEpisodeNumber()], ['Episode Title', $e->getName()], ['Origin Country', $country], ['Air Date', $e->getAirDate()->format('Y\\-m\\-d')], ['Size', $fileSize], ['API Match', sprintf('<fg=green>OKAY: %d/%d</>', $s->getId(), $e->getId())]]; $this->ioVerbose(function (StyleInterface $style) use($rows) { $style->table($rows, []); }); $rows = [['File Path', $f->getFile()->getPathname()], ['Show Name', $s->getName()], ['Season/Episode', sprintf('%d/%d', $e->getSeasonNumber(), $e->getEpisodeNumber())], ['Episode Title', $e->getName()], ['Size', $fileSize], ['API Match', sprintf('<fg=green>OKAY: %d/%d</>', $s->getId(), $e->getId())]]; $this->ioNotVerbose(function (StyleInterface $style) use($rows) { $style->table($rows, []); }); }
/** * @test */ public function shouldWatchlistTvObject() { $repository = $this->getRepositoryWithMockedHttpAdapter(); $this->getAdapter()->expects($this->once())->method('post')->with($this->getRequest('account/' . self::ACCOUNT_ID . '/watchlist', [], 'POST', [], ['media_id' => self::MOVIE_ID, 'media_type' => 'tv', 'watchlist' => true])); $tv = new Tv(); $tv->setId(self::MOVIE_ID); $repository->watchlist(self::ACCOUNT_ID, $tv, true); }
/** * @param array $data * * @return Tv */ public function create(array $data = array()) { if (!$data) { return null; } $tvShow = new Tv(); if (array_key_exists('credits', $data)) { if (array_key_exists('cast', $data['credits'])) { $tvShow->getCredits()->setCast($this->getCastFactory()->createCollection($data['credits']['cast'], new CastMember())); } if (array_key_exists('crew', $data['credits'])) { $tvShow->getCredits()->setCrew($this->getCrewFactory()->createCollection($data['credits']['crew'], new CrewMember())); } } /** External ids */ if (array_key_exists('external_ids', $data)) { $tvShow->setExternalIds($this->hydrate(new ExternalIds(), $data['external_ids'])); } /** Genres */ if (array_key_exists('genres', $data)) { $tvShow->setGenres($this->getGenreFactory()->createCollection($data['genres'])); } /** Images */ if (array_key_exists('images', $data)) { $tvShow->setImages($this->getImageFactory()->createCollectionFromTv($data['images'])); } if (array_key_exists('backdrop_path', $data)) { $tvShow->setBackdropImage($this->getImageFactory()->createFromPath($data['backdrop_path'], 'backdrop_path')); } if (array_key_exists('poster_path', $data)) { $tvShow->setPosterImage($this->getImageFactory()->createFromPath($data['poster_path'], 'poster_path')); } /** Translations */ if (array_key_exists('translations', $data) && null !== $data['translations']) { if (array_key_exists('translations', $data['translations'])) { $translations = $data['translations']['translations']; } else { $translations = $data['translations']; } $tvShow->setTranslations($this->createGenericCollection($translations, new Translation())); } /** Seasons */ if (array_key_exists('seasons', $data)) { $tvShow->setSeasons($this->getTvSeasonFactory()->createCollection($data['seasons'])); } /** Networks */ if (array_key_exists('networks', $data)) { $tvShow->setNetworks($this->getNetworkFactory()->createCollection($data['networks'])); } if (array_key_exists('videos', $data)) { $tvShow->setVideos($this->getVideoFactory()->createCollection($data['videos'])); } if (array_key_exists('keywords', $data) && array_key_exists('results', $data['keywords'])) { $tvShow->setKeywords($this->getKeywordFactory()->createCollection($data['keywords']['results'])); } if (array_key_exists('changes', $data)) { $tvShow->setChanges($this->getChangesFactory()->createCollection($data['changes'])); } if (array_key_exists('similar', $data)) { $tvShow->setSimilar($this->createResultCollection($data['similar'])); } if (array_key_exists('languages', $data)) { $collection = new GenericCollection(); foreach ($data['languages'] as $iso6391) { $object = new SpokenLanguage(); $object->setIso6391($iso6391); $collection->add(null, $object); } $tvShow->setLanguages($collection); } if (array_key_exists('origin_country', $data)) { $collection = new GenericCollection(); foreach ($data['origin_country'] as $iso31661) { $object = new Country(); $object->setIso31661($iso31661); $collection->add(null, $object); } $tvShow->setOriginCountry($collection); } if (array_key_exists('created_by', $data)) { $collection = new GenericCollection(); $factory = new PeopleFactory(); foreach ($data['created_by'] as $castMember) { $object = $factory->create($castMember, new CastMember()); $collection->add(null, $object); } $tvShow->setCreatedBy($collection); } return $this->hydrate($tvShow, $data); }