Skip to content

Commit

Permalink
Updating TvEpisodeRepository
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfzdotnet committed Feb 23, 2014
1 parent c134d5d commit 6b67c60
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 9 deletions.
1 change: 1 addition & 0 deletions lib/Tmdb/Model/AbstractModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ class AbstractModel {
* @var array
*/
public static $_properties = array();

}
54 changes: 45 additions & 9 deletions lib/Tmdb/Repository/TvEpisodeRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,28 @@ public function load($tvShow, $season, $episode, array $parameters = array(), ar
*
* Just like the website, we pull this information from the last season of the series.
*
* @param $id
* @param $tvShow
* @param $season
* @param $episode
* @param $parameters
* @param $headers
* @return null|\Tmdb\Model\AbstractModel
*/
public function getCredits($id, $season, $episode, array $parameters = array(), array $headers = array())
public function getCredits($tvShow, $season, $episode, array $parameters = array(), array $headers = array())
{
$data = $this->getApi()->getCredits($id, $season, $episode, $this->parseQueryParameters($parameters), $headers);
if ($tvShow instanceof Tv) {
$tvShow = $tvShow->getId();
}

if ($season instanceof Season) {
$season = $season->getId();
}

if ($episode instanceof Tv\Episode) {
$episode = $episode->getId();
}

$data = $this->getApi()->getCredits($tvShow, $season, $episode, $this->parseQueryParameters($parameters), $headers);
$episode = $this->getFactory()->create(array('credits' => $data));

return $episode->getCredits();
Expand All @@ -90,16 +102,28 @@ public function getCredits($id, $season, $episode, array $parameters = array(),
/**
* Get the external ids that we have stored for a TV series.
*
* @param $id
* @param $tvShow
* @param $season
* @param $episode
* @param $parameters
* @param $headers
* @return null|\Tmdb\Model\AbstractModel
*/
public function getExternalIds($id, $season, $episode, array $parameters = array(), array $headers = array())
public function getExternalIds($tvShow, $season, $episode, array $parameters = array(), array $headers = array())
{
$data = $this->getApi()->getExternalIds($id, $season, $episode, $this->parseQueryParameters($parameters), $headers);
if ($tvShow instanceof Tv) {
$tvShow = $tvShow->getId();
}

if ($season instanceof Season) {
$season = $season->getId();
}

if ($episode instanceof Tv\Episode) {
$episode = $episode->getId();
}

$data = $this->getApi()->getExternalIds($tvShow, $season, $episode, $this->parseQueryParameters($parameters), $headers);
$episode = $this->getFactory()->create(array('external_ids' => $data));

return $episode->getExternalIds();
Expand All @@ -108,16 +132,28 @@ public function getExternalIds($id, $season, $episode, array $parameters = array
/**
* Get the images (posters and backdrops) for a TV series.
*
* @param $id
* @param $tvShow
* @param $season
* @param $episode
* @param $parameters
* @param $headers
* @return null|\Tmdb\Model\AbstractModel
*/
public function getImages($id, $season, $episode, array $parameters = array(), array $headers = array())
public function getImages($tvShow, $season, $episode, array $parameters = array(), array $headers = array())
{
$data = $this->getApi()->getImages($id, $season, $episode, $this->parseQueryParameters($parameters), $headers);
if ($tvShow instanceof Tv) {
$tvShow = $tvShow->getId();
}

if ($season instanceof Season) {
$season = $season->getId();
}

if ($episode instanceof Tv\Episode) {
$episode = $episode->getId();
}

$data = $this->getApi()->getImages($tvShow, $season, $episode, $this->parseQueryParameters($parameters), $headers);
$episode = $this->getFactory()->create(array('images' => $data));

return $episode->getImages();
Expand Down
57 changes: 57 additions & 0 deletions test/Tmdb/Tests/Repository/TvEpisodeRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,63 @@ public function shouldBeAbleToLoadTvSeasonWithTvAndSeason()
$repository->load($tv, $season, $episode);
}

/**
* @test
*/
public function shouldGetCredits()
{
$repository = $this->getRepositoryWithMockedHttpClient();

$tv = new Tv();
$tv->setId(self::TV_ID);

$season = new Season();
$season->setId(self::SEASON_ID);

$episode = new Episode();
$episode->setId(self::EPISODE_ID);

$repository->getCredits($tv, $season, $episode);
}

/**
* @test
*/
public function shouldGetExternalIds()
{
$repository = $this->getRepositoryWithMockedHttpClient();

$tv = new Tv();
$tv->setId(self::TV_ID);

$season = new Season();
$season->setId(self::SEASON_ID);

$episode = new Episode();
$episode->setId(self::EPISODE_ID);

$repository->getExternalIds($tv, $season, $episode);
}

/**
* @test
*/
public function shouldGetImages()
{
$repository = $this->getRepositoryWithMockedHttpClient();

$tv = new Tv();
$tv->setId(self::TV_ID);

$season = new Season();
$season->setId(self::SEASON_ID);

$episode = new Episode();
$episode->setId(self::EPISODE_ID);

$repository->getImages($tv, $season, $episode);
}

/**
* @expectedException Tmdb\Exception\RuntimeException
* @test
Expand Down

0 comments on commit 6b67c60

Please sign in to comment.