Skip to content

Commit dbda108

Browse files
geochatzwtfzdotnet
authored andcommitted
Fixed Episode and Season Repositories (#127)
* Fixed the Season and Episode parameters on EpisodeRepository->load() When fetching for a TV Episode we need the TV Show ID, Season Number and, Episode Number and not the Season->id and Episode->id * Changed null check with is_null Changed the check with the is_null function because there is a chance that there is a Season 0 for a TV Show. When the Season is 0 then the $season == null returns true. * Changed default parameters For Episodes the API needs the Season No and the Episode No and not the TMDB ID * Changed the SeasonID with Season Number For all the Season API calls we need the Season Number and not the Season TMDB ID * Fix Test Set SeasonNumber and EpisodeNumber as they are required by the TvEpisodeRepository and TMDB API * Fix TvEpisodeRepository and TvSeasonRepository Tests * Fixed TvEpisodeRepositoryTest I replaced the SEASON_ID to SEASON_NUMBER as this is what we need. * Fix TvEpisodeRepositoryTest (shouldThrowExceptionWhenConditionsNotMet)
1 parent 3ecf3d0 commit dbda108

File tree

4 files changed

+43
-43
lines changed

4 files changed

+43
-43
lines changed

lib/Tmdb/Repository/TvEpisodeRepository.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ public function load($tvShow, $season, $episode, array $parameters = [], array $
5151
}
5252

5353
if ($season instanceof Season) {
54-
$season = $season->getId();
54+
$season = $season->getSeasonNumber();
5555
}
5656

5757
if ($episode instanceof Tv\Episode) {
58-
$episode = $episode->getId();
58+
$episode = $episode->getEpisodeNumber();
5959
}
6060

61-
if (null == $tvShow || null == $season || null == $episode) {
61+
if (is_null($tvShow) || is_null($season) || is_null($episode) ) {
6262
throw new RuntimeException('Not all required parameters to load an tv episode are present.');
6363
}
6464

@@ -104,11 +104,11 @@ public function getCredits($tvShow, $season, $episode, array $parameters = [], a
104104
}
105105

106106
if ($season instanceof Season) {
107-
$season = $season->getId();
107+
$season = $season->getSeasonNumber();
108108
}
109109

110110
if ($episode instanceof Tv\Episode) {
111-
$episode = $episode->getId();
111+
$episode = $episode->getEpisodeNumber();
112112
}
113113

114114
$data = $this->getApi()->getCredits(
@@ -141,11 +141,11 @@ public function getExternalIds($tvShow, $season, $episode, array $parameters = [
141141
}
142142

143143
if ($season instanceof Season) {
144-
$season = $season->getId();
144+
$season = $season->getSeasonNumber();
145145
}
146146

147147
if ($episode instanceof Tv\Episode) {
148-
$episode = $episode->getId();
148+
$episode = $episode->getEpisodeNumber();
149149
}
150150

151151
$data = $this->getApi()->getExternalIds(
@@ -178,11 +178,11 @@ public function getImages($tvShow, $season, $episode, array $parameters = [], ar
178178
}
179179

180180
if ($season instanceof Season) {
181-
$season = $season->getId();
181+
$season = $season->getSeasonNumber();
182182
}
183183

184184
if ($episode instanceof Tv\Episode) {
185-
$episode = $episode->getId();
185+
$episode = $episode->getEpisodeNumber();
186186
}
187187

188188
$data = $this->getApi()->getImages(
@@ -215,11 +215,11 @@ public function getVideos($tvShow, $season, $episode, array $parameters = [], ar
215215
}
216216

217217
if ($season instanceof Season) {
218-
$season = $season->getId();
218+
$season = $season->getSeasonNumber();
219219
}
220220

221221
if ($episode instanceof Tv\Episode) {
222-
$episode = $episode->getId();
222+
$episode = $episode->getEpisodeNumber();
223223
}
224224

225225
$data = $this->getApi()->getVideos(
@@ -253,11 +253,11 @@ public function getAccountStates($tvShow, $season, $episode)
253253
}
254254

255255
if ($season instanceof Season) {
256-
$season = $season->getId();
256+
$season = $season->getSeasonNumber();
257257
}
258258

259259
if ($episode instanceof Tv\Episode) {
260-
$episode = $episode->getId();
260+
$episode = $episode->getEpisodeNumber();
261261
}
262262

263263
return $this->getFactory()->createAccountStates(
@@ -283,11 +283,11 @@ public function rate($tvShow, $season, $episode, $rating)
283283
}
284284

285285
if ($season instanceof Season) {
286-
$season = $season->getId();
286+
$season = $season->getSeasonNumber();
287287
}
288288

289289
if ($episode instanceof Tv\Episode) {
290-
$episode = $episode->getId();
290+
$episode = $episode->getEpisodeNumber();
291291
}
292292

293293
return $this->getFactory()->createResult(

lib/Tmdb/Repository/TvSeasonRepository.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public function getCredits($tvShow, $season, array $parameters = [], array $head
8888
}
8989

9090
if ($season instanceof Season) {
91-
$season = $season->getId();
91+
$season = $season->getSeasonNumber();
9292
}
9393

9494
$data = $this->getApi()->getCredits($tvShow, $season, $this->parseQueryParameters($parameters), $headers);
@@ -113,7 +113,7 @@ public function getExternalIds($tvShow, $season, array $parameters = [], array $
113113
}
114114

115115
if ($season instanceof Season) {
116-
$season = $season->getId();
116+
$season = $season->getSeasonNumber();
117117
}
118118

119119
$data = $this->getApi()->getExternalIds($tvShow, $season, $this->parseQueryParameters($parameters), $headers);
@@ -138,7 +138,7 @@ public function getImages($tvShow, $season, array $parameters = [], array $heade
138138
}
139139

140140
if ($season instanceof Season) {
141-
$season = $season->getId();
141+
$season = $season->getSeasonNumber();
142142
}
143143

144144
$data = $this->getApi()->getImages($tvShow, $season, $this->parseQueryParameters($parameters), $headers);
@@ -163,7 +163,7 @@ public function getVideos($tvShow, $season, array $parameters = [], array $heade
163163
}
164164

165165
if ($season instanceof Season) {
166-
$season = $season->getId();
166+
$season = $season->getSeasonNumber();
167167
}
168168

169169
$data = $this->getApi()->getVideos($tvShow, $season, $this->parseQueryParameters($parameters), $headers);

test/Tmdb/Tests/Repository/TvEpisodeRepositoryTest.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
class TvEpisodeRepositoryTest extends TestCase
2020
{
2121
const TV_ID = 3572;
22-
const SEASON_ID = 1;
23-
const EPISODE_ID = 1;
22+
const SEASON_NUMBER = 1;
23+
const EPISODE_NUMBER = 1;
2424

2525
/**
2626
* @test
@@ -32,12 +32,12 @@ public function shouldLoadTvEpisode()
3232
$this->getAdapter()->expects($this->once())
3333
->method('get')
3434
->with($this->getRequest(
35-
'https://api.themoviedb.org/3/tv/' . self::TV_ID . '/season/' . self::SEASON_ID . '/episode/' . self::EPISODE_ID,
35+
'https://api.themoviedb.org/3/tv/' . self::TV_ID . '/season/' . self::SEASON_NUMBER . '/episode/' . self::EPISODE_NUMBER,
3636
['append_to_response' => 'credits,external_ids,images,changes,videos']
3737
))
3838
;
3939

40-
$repository->load(self::TV_ID, self::SEASON_ID, self::EPISODE_ID);
40+
$repository->load(self::TV_ID, self::SEASON_NUMBER, self::EPISODE_NUMBER);
4141
}
4242

4343
/**
@@ -50,7 +50,7 @@ public function shouldBeAbleToLoadTvSeasonWithTvAndSeason()
5050
$this->getAdapter()->expects($this->once())
5151
->method('get')
5252
->with($this->getRequest(
53-
'https://api.themoviedb.org/3/tv/' . self::TV_ID . '/season/' . self::SEASON_ID . '/episode/' . self::EPISODE_ID,
53+
'https://api.themoviedb.org/3/tv/' . self::TV_ID . '/season/' . self::SEASON_NUMBER . '/episode/' . self::EPISODE_NUMBER,
5454
['append_to_response' => 'credits,external_ids,images,changes,videos']
5555
))
5656
;
@@ -59,10 +59,10 @@ public function shouldBeAbleToLoadTvSeasonWithTvAndSeason()
5959
$tv->setId(self::TV_ID);
6060

6161
$season = new Season();
62-
$season->setId(self::SEASON_ID);
62+
$season->setSeasonNumber(self::SEASON_NUMBER);
6363

6464
$episode = new Episode();
65-
$episode->setId(self::EPISODE_ID);
65+
$episode->setEpisodeNumber(self::EPISODE_NUMBER);
6666

6767
$repository->load($tv, $season, $episode);
6868
}
@@ -77,18 +77,18 @@ public function shouldGetCredits()
7777
$this->getAdapter()->expects($this->once())
7878
->method('get')
7979
->with($this->getRequest(
80-
'https://api.themoviedb.org/3/tv/' . self::TV_ID . '/season/' . self::SEASON_ID . '/episode/' . self::EPISODE_ID . '/credits'
80+
'https://api.themoviedb.org/3/tv/' . self::TV_ID . '/season/' . self::SEASON_NUMBER . '/episode/' . self::EPISODE_NUMBER . '/credits'
8181
))
8282
;
8383

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

8787
$season = new Season();
88-
$season->setId(self::SEASON_ID);
88+
$season->setSeasonNumber(self::SEASON_NUMBER);
8989

9090
$episode = new Episode();
91-
$episode->setId(self::EPISODE_ID);
91+
$episode->setEpisodeNumber(self::EPISODE_NUMBER);
9292

9393
$repository->getCredits($tv, $season, $episode);
9494
}
@@ -103,18 +103,18 @@ public function shouldGetExternalIds()
103103
$this->getAdapter()->expects($this->once())
104104
->method('get')
105105
->with($this->getRequest(
106-
'https://api.themoviedb.org/3/tv/' . self::TV_ID . '/season/' . self::SEASON_ID . '/episode/' . self::EPISODE_ID . '/external_ids'
106+
'https://api.themoviedb.org/3/tv/' . self::TV_ID . '/season/' . self::SEASON_NUMBER . '/episode/' . self::EPISODE_NUMBER . '/external_ids'
107107
))
108108
;
109109

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

113113
$season = new Season();
114-
$season->setId(self::SEASON_ID);
114+
$season->setSeasonNumber(self::SEASON_NUMBER);
115115

116116
$episode = new Episode();
117-
$episode->setId(self::EPISODE_ID);
117+
$episode->setEpisodeNumber(self::EPISODE_NUMBER);
118118

119119
$repository->getExternalIds($tv, $season, $episode);
120120
}
@@ -129,18 +129,18 @@ public function shouldGetImages()
129129
$this->getAdapter()->expects($this->once())
130130
->method('get')
131131
->with($this->getRequest(
132-
'https://api.themoviedb.org/3/tv/' . self::TV_ID . '/season/' . self::SEASON_ID . '/episode/' . self::EPISODE_ID . '/images'
132+
'https://api.themoviedb.org/3/tv/' . self::TV_ID . '/season/' . self::SEASON_NUMBER . '/episode/' . self::EPISODE_NUMBER . '/images'
133133
))
134134
;
135135

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

139139
$season = new Season();
140-
$season->setId(self::SEASON_ID);
140+
$season->setSeasonNumber(self::SEASON_NUMBER);
141141

142142
$episode = new Episode();
143-
$episode->setId(self::EPISODE_ID);
143+
$episode->setEpisodeNumber(self::EPISODE_NUMBER);
144144

145145
$repository->getImages($tv, $season, $episode);
146146
}
@@ -155,18 +155,18 @@ public function shouldGetVideos()
155155
$this->getAdapter()->expects($this->once())
156156
->method('get')
157157
->with($this->getRequest(
158-
'https://api.themoviedb.org/3/tv/' . self::TV_ID . '/season/' . self::SEASON_ID . '/episode/' . self::EPISODE_ID . '/videos'
158+
'https://api.themoviedb.org/3/tv/' . self::TV_ID . '/season/' . self::SEASON_NUMBER . '/episode/' . self::EPISODE_NUMBER . '/videos'
159159
))
160160
;
161161

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

165165
$season = new Season();
166-
$season->setId(self::SEASON_ID);
166+
$season->setSeasonNumber(self::SEASON_NUMBER);
167167

168168
$episode = new Episode();
169-
$episode->setId(self::EPISODE_ID);
169+
$episode->setEpisodeNumber(self::EPISODE_NUMBER);
170170

171171
$repository->getVideos($tv, $season, $episode);
172172
}
@@ -183,7 +183,7 @@ public function shouldThrowExceptionWhenConditionsNotMet()
183183
$tv->setId(self::TV_ID);
184184

185185
$season = new Season();
186-
$season->setId(self::SEASON_ID);
186+
$season->setSeasonNumber(self::SEASON_NUMBER);
187187

188188
$repository->load($tv, $season, null);
189189
}

test/Tmdb/Tests/Repository/TvSeasonRepositoryTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function shouldGetCredits()
7979
$tv->setId(self::TV_ID);
8080

8181
$season = new Tv\Season();
82-
$season->setId(self::SEASON_NUMBER);
82+
$season->setSeasonNumber(self::SEASON_NUMBER);
8383

8484
$repository->getCredits($tv, $season);
8585
}
@@ -102,7 +102,7 @@ public function shouldGetExternalIds()
102102
$tv->setId(self::TV_ID);
103103

104104
$season = new Tv\Season();
105-
$season->setId(self::SEASON_NUMBER);
105+
$season->setSeasonNumber(self::SEASON_NUMBER);
106106

107107
$repository->getExternalIds($tv, $season);
108108
}
@@ -125,7 +125,7 @@ public function shouldGetImages()
125125
$tv->setId(self::TV_ID);
126126

127127
$season = new Tv\Season();
128-
$season->setId(self::SEASON_NUMBER);
128+
$season->setSeasonNumber(self::SEASON_NUMBER);
129129

130130
$repository->getImages($tv, $season);
131131
}
@@ -148,7 +148,7 @@ public function shouldGetVideos()
148148
$tv->setId(self::TV_ID);
149149

150150
$season = new Tv\Season();
151-
$season->setId(self::SEASON_NUMBER);
151+
$season->setSeasonNumber(self::SEASON_NUMBER);
152152

153153
$repository->getVideos($tv, $season);
154154
}

0 commit comments

Comments
 (0)