diff --git a/lib/Tmdb/Factory/ImageFactory.php b/lib/Tmdb/Factory/ImageFactory.php index 56c3f44d..1cb7a1d1 100644 --- a/lib/Tmdb/Factory/ImageFactory.php +++ b/lib/Tmdb/Factory/ImageFactory.php @@ -64,11 +64,7 @@ public function createFromPath($path, $key) */ public function createMediaImage(array $data = []) { - if (!array_key_exists('image_type', $data)) { - throw new \RuntimeException('Unable to detect the image type.'); - } - - $type = $this->resolveImageType($data['image_type']); + $type = $this->resolveImageType(array_key_exists('image_type', $data) ? $data['image_type'] : null); $image = $this->hydrate($type, $data); if (array_key_exists('media', $data) && array_key_exists('media_type', $data)) { @@ -109,7 +105,7 @@ public function createMediaImage(array $data = []) $image->setMedia($media); } - return $this->hydrate($type, $data); + return $image; } /** diff --git a/test/Tmdb/Tests/Factory/ImageFactoryTest.php b/test/Tmdb/Tests/Factory/ImageFactoryTest.php index 93c89b7d..46a4abc1 100644 --- a/test/Tmdb/Tests/Factory/ImageFactoryTest.php +++ b/test/Tmdb/Tests/Factory/ImageFactoryTest.php @@ -186,6 +186,16 @@ public function shouldFilterMaxWidth() } } + /** + * @test + */ + public function shouldSetMedia() + { + $image = $this->getFactory()->createMediaImage($this->loadByFile('images/tagged_image.json')); + + $this->assertInstanceOf('Tmdb\Model\Movie', $image->getMedia()); + } + protected function getFactoryClass() { return 'Tmdb\Factory\ImageFactory'; diff --git a/test/Tmdb/Tests/Resources/images/tagged_image.json b/test/Tmdb/Tests/Resources/images/tagged_image.json new file mode 100644 index 00000000..c5be47b4 --- /dev/null +++ b/test/Tmdb/Tests/Resources/images/tagged_image.json @@ -0,0 +1,29 @@ +{ + "iso_639_1": null, + "vote_count": 72, + "media_type": "movie", + "file_path": "/lIv1QinFqz4dlp5U4lQ6HaiskOZ.jpg", + "aspect_ratio": 0.66666666666667, + "media": { + "release_date": "2014-10-10", + "vote_count": 3749, + "video": false, + "adult": false, + "vote_average": 8.3, + "title": "Whiplash", + "genre_ids": [ + 18, + 10402 + ], + "original_language": "en", + "original_title": "Whiplash", + "popularity": 11.036484, + "id": 244786, + "backdrop_path": "/6bbZ6XyvgfjhQwbplnUh1LSj1ky.jpg", + "overview": "A talented young drummer begins to pursue perfection.", + "poster_path": "/lIv1QinFqz4dlp5U4lQ6HaiskOZ.jpg" + }, + "height": 2100, + "vote_average": 6.424, + "width": 1400 +}