diff --git a/lib/Tmdb/Factory/MovieFactory.php b/lib/Tmdb/Factory/MovieFactory.php index 9c992b04..49d04f8b 100644 --- a/lib/Tmdb/Factory/MovieFactory.php +++ b/lib/Tmdb/Factory/MovieFactory.php @@ -129,23 +129,23 @@ public function create(array $data = array()) $movie->setKeywords($this->getKeywordFactory()->createCollection($data['keywords'])); } - if (array_key_exists('releases', $data)) { + if (array_key_exists('releases', $data) && array_key_exists('countries', $data['releases'])) { $movie->setReleases($this->createGenericCollection($data['releases']['countries'], new Movie\Release())); } /** * @TODO actually implement more providers? ( Can't seem to find any quicktime related trailers anyways? ). For now KISS */ - if (array_key_exists('trailers', $data)) { + if (array_key_exists('trailers', $data) && array_key_exists('youtube', $data['trailers'])) { $movie->setTrailers($this->createGenericCollection($data['trailers']['youtube'], new Youtube())); } - if (array_key_exists('translations', $data)) { + if (array_key_exists('translations', $data) && array_key_exists('translations', $data['translations'])) { $movie->setTranslations($this->createGenericCollection($data['translations']['translations'], new Translation())); } if (array_key_exists('similar_movies', $data)) { - $movie->setSimilarMovies($this->createCollection($data['similar_movies']['results'])); + $movie->setSimilarMovies($this->createResultCollection($data['similar_movies'])); } if (array_key_exists('reviews', $data)) { diff --git a/test/Tmdb/Tests/Repository/MovieRepositoryTest.php b/test/Tmdb/Tests/Repository/MovieRepositoryTest.php index f015ae9c..49b83795 100644 --- a/test/Tmdb/Tests/Repository/MovieRepositoryTest.php +++ b/test/Tmdb/Tests/Repository/MovieRepositoryTest.php @@ -12,6 +12,8 @@ */ namespace Tmdb\Tests\Repository; +use Tmdb\Repository\MovieRepository; + class MovieRepositoryTest extends TestCase { const MOVIE_ID = 120; @@ -26,6 +28,117 @@ public function shouldLoadMovie() $repository->load(self::MOVIE_ID); } + /** + * @test + */ + public function shouldGetAlternativeTitles() + { + $repository = $this->getRepositoryWithMockedHttpClient(); + + $repository->getAlternativeTitles(self::MOVIE_ID); + } + + /** + * @test + */ + public function shouldGetCredits() + { + $repository = $this->getRepositoryWithMockedHttpClient(); + + $repository->getCredits(self::MOVIE_ID); + } + + /** + * @test + */ + public function shouldGetImages() + { + $repository = $this->getRepositoryWithMockedHttpClient(); + + $repository->getImages(self::MOVIE_ID); + } + + /** + * @test + */ + public function shouldGetKeywords() + { + $repository = $this->getRepositoryWithMockedHttpClient(); + + $repository->getKeywords(self::MOVIE_ID); + } + + /** + * @test + */ + public function shouldGetReleases() + { + $repository = $this->getRepositoryWithMockedHttpClient(); + + $repository->getReleases(self::MOVIE_ID); + } + + /** + * @test + */ + public function shouldGetTrailers() + { + $repository = $this->getRepositoryWithMockedHttpClient(); + + $repository->getTrailers(self::MOVIE_ID); + } + + /** + * @test + */ + public function shouldGetTranslations() + { + $repository = $this->getRepositoryWithMockedHttpClient(); + + $repository->getTranslations(self::MOVIE_ID); + } + + /** + * @test + */ + public function shouldGetSimilarMovies() + { + $repository = $this->getRepositoryWithMockedHttpClient(); + + $repository->getSimilarMovies(self::MOVIE_ID); + } + + /** + * @test + */ + public function shouldGetReviews() + { + $repository = $this->getRepositoryWithMockedHttpClient(); + + $repository->getReviews(self::MOVIE_ID); + } + + /** + * @test + * @todo FIX + */ + public function shouldGetLists() + { +// $repository = $this->getRepositoryWithMockedHttpClient(); +// +// $repository->getLists(self::MOVIE_ID); + } + + /** + * @test + */ + public function shouldGetChanges() + { + $repository = $this->getRepositoryWithMockedHttpClient(); + + $repository->getChanges(self::MOVIE_ID); + } + /** * @test */ @@ -76,6 +189,26 @@ public function shouldGetTopRated() $repository->getTopRated(); } + /** + * @test + */ + public function shouldBeAbleToSetFactories() + { + /** + * @var MovieRepository $repository + */ + $repository = $this->getRepositoryWithMockedHttpClient(); + $class = new \stdClass(); + + $repository->setAlternativeTitlesFactory($class); + $repository->setImagesFactory($class); + $repository->setPeopleFactory($class); + + $this->assertInstanceOf('stdClass', $repository->getAlternativeTitlesFactory()); + $this->assertInstanceOf('stdClass', $repository->getImagesFactory()); + $this->assertInstanceOf('stdClass', $repository->getPeopleFactory()); + } + protected function getApiClass() { return 'Tmdb\Api\Movies';