Skip to content

Commit 45f59e7

Browse files
Fluxliciouswtfzdotnet
authored andcommitted
Fixed bug where filterBestVotedImage() would return null when all images have no rating. When voteAverage is 0 for all images it will return the first occurrence. (#175)
1 parent 2a27134 commit 45f59e7

3 files changed

Lines changed: 155 additions & 1 deletion

File tree

lib/Tmdb/Model/Collection/Images.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ function ($key, $value) use ($height) {
197197
public function filterBestVotedImage()
198198
{
199199
$currentImage = null;
200-
$voteAverage = 0;
200+
$voteAverage = -1;
201201

202202
/**
203203
* @var $image Image

test/Tmdb/Tests/Factory/ImageFactoryTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,18 @@ public function shouldSetMedia()
196196
$this->assertInstanceOf('Tmdb\Model\Movie', $image->getMedia());
197197
}
198198

199+
/**
200+
* @test
201+
*/
202+
203+
public function shouldFilterBestVotedImage() {
204+
$collection = $this->getFactory()->createImageCollection($this->loadByFile('images/movie_novotes.json'));
205+
206+
$poster = $collection->filterPosters()->filterBestVotedImage();
207+
208+
$this->assertInstanceOf('Tmdb\Model\Image\PosterImage', $poster);
209+
}
210+
199211
protected function getFactoryClass()
200212
{
201213
return 'Tmdb\Factory\ImageFactory';
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
{
2+
"id": 550,
3+
"backdrops": [
4+
{
5+
"file_path": "/8uO0gUM8aNqYLs1OsTBQiXu0fEv.jpg",
6+
"width": 1280,
7+
"height": 720,
8+
"iso_639_1": null,
9+
"aspect_ratio": 1.78,
10+
"vote_average": 0,
11+
"vote_count": 0
12+
},
13+
{
14+
"file_path": "/8T0hpqWsgzKhWGsXGD8ilkwRPkC.jpg",
15+
"width": 1280,
16+
"height": 720,
17+
"iso_639_1": null,
18+
"aspect_ratio": 1.78,
19+
"vote_average": 0,
20+
"vote_count": 0
21+
},
22+
{
23+
"file_path": "/hNFMawyNDWZKKHU4GYCBz1krsRM.jpg",
24+
"width": 1280,
25+
"height": 720,
26+
"iso_639_1": null,
27+
"aspect_ratio": 1.78,
28+
"vote_average": 0,
29+
"vote_count": 0
30+
},
31+
{
32+
"file_path": "/mMZRKb3NVo5ZeSPEIaNW9buLWQ0.jpg",
33+
"width": 1920,
34+
"height": 1080,
35+
"iso_639_1": null,
36+
"aspect_ratio": 1.78,
37+
"vote_average": 0,
38+
"vote_count": 0
39+
},
40+
{
41+
"file_path": "/9Kr6UzouF674Smw3D9Hp2DlH1Vo.jpg",
42+
"width": 1280,
43+
"height": 720,
44+
"iso_639_1": null,
45+
"aspect_ratio": 1.78,
46+
"vote_average": 0,
47+
"vote_count": 0
48+
},
49+
{
50+
"file_path": "/eTVdpy2JXaGFit2V2ToZ79v9D7R.jpg",
51+
"width": 1920,
52+
"height": 1080,
53+
"iso_639_1": null,
54+
"aspect_ratio": 1.78,
55+
"vote_average": 0,
56+
"vote_count": 0
57+
},
58+
{
59+
"file_path": "/fuSeIUKsizmfiPIwDH7lKiFNQoD.jpg",
60+
"width": 1280,
61+
"height": 720,
62+
"iso_639_1": null,
63+
"aspect_ratio": 1.78,
64+
"vote_average": 0,
65+
"vote_count": 0
66+
}
67+
],
68+
"posters": [
69+
{
70+
"file_path": "/2lECpi35Hnbpa4y46JX0aY3AWTy.jpg",
71+
"width": 1000,
72+
"height": 1500,
73+
"iso_639_1": "en",
74+
"aspect_ratio": 0.67000000000000004,
75+
"vote_average": 0,
76+
"vote_count": 0
77+
},
78+
{
79+
"file_path": "/shFj1K58Tn55Qz2p2v0RqxXiXyo.jpg",
80+
"width": 1000,
81+
"height": 1408,
82+
"iso_639_1": "en",
83+
"aspect_ratio": 0.70999999999999996,
84+
"vote_average": 0,
85+
"vote_count": 0
86+
},
87+
{
88+
"file_path": "/jQ2iUsXI2jmUcOFGjOaONCLwaVp.jpg",
89+
"width": 675,
90+
"height": 1000,
91+
"iso_639_1": "en",
92+
"aspect_ratio": 0.68000000000000005,
93+
"vote_average": 0,
94+
"vote_count": 0
95+
},
96+
{
97+
"file_path": "/6cMPLU1jv8pG9BMmieXCHDTVRPm.jpg",
98+
"width": 1479,
99+
"height": 2166,
100+
"iso_639_1": "es",
101+
"aspect_ratio": 0.68000000000000005,
102+
"vote_average": 0,
103+
"vote_count": 0
104+
},
105+
{
106+
"file_path": "/pKGrxTB35AkLsZCT8d8h6F9BSMN.jpg",
107+
"width": 1000,
108+
"height": 1500,
109+
"iso_639_1": "en",
110+
"aspect_ratio": 0.67000000000000004,
111+
"vote_average": 0,
112+
"vote_count": 0
113+
},
114+
{
115+
"file_path": "/5qEBvDRdY2S2CJ9tsoFktIt8Xue.jpg",
116+
"width": 2689,
117+
"height": 3539,
118+
"iso_639_1": "es",
119+
"aspect_ratio": 0.76000000000000001,
120+
"vote_average": 0,
121+
"vote_count": 0
122+
},
123+
{
124+
"file_path": "/1dTxsr21UmFewu2CJ886JNqqkqn.jpg",
125+
"width": 2030,
126+
"height": 3000,
127+
"iso_639_1": "en",
128+
"aspect_ratio": 0.68000000000000005,
129+
"vote_average": 0,
130+
"vote_count": 0
131+
},
132+
{
133+
"file_path": "/olTEZdZJ7UKLE1o4hkFDq4jXBs8.jpg",
134+
"width": 713,
135+
"height": 1002,
136+
"iso_639_1": "hu",
137+
"aspect_ratio": 0.70999999999999996,
138+
"vote_average": 0,
139+
"vote_count": 0
140+
}
141+
]
142+
}

0 commit comments

Comments
 (0)