Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions lib/Tmdb/Factory/ImageFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -109,7 +105,7 @@ public function createMediaImage(array $data = [])
$image->setMedia($media);
}

return $this->hydrate($type, $data);
return $image;
}

/**
Expand Down
10 changes: 10 additions & 0 deletions test/Tmdb/Tests/Factory/ImageFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
29 changes: 29 additions & 0 deletions test/Tmdb/Tests/Resources/images/tagged_image.json
Original file line number Diff line number Diff line change
@@ -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
}