Skip to content

Commit 5a92fc2

Browse files
committed
Added tv watch providers tests
1 parent c295875 commit 5a92fc2

6 files changed

Lines changed: 936 additions & 1 deletion

File tree

lib/Tmdb/Api/Tv.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,19 @@ public function getVideos($tvshow_id, array $parameters = [], array $headers = [
169169
return $this->get('tv/' . $tvshow_id . '/videos', $parameters, $headers);
170170
}
171171

172+
/**
173+
* Get the watch providers (by region) for a specific movie id.
174+
*
175+
* @param $movie_id
176+
* @param array $parameters
177+
* @param array $headers
178+
* @return mixed
179+
*/
180+
public function getWatchProviders($tvshow_id, array $parameters = [], array $headers = [])
181+
{
182+
return $this->get('tv/' . $tvshow_id . '/watch/providers', $parameters, $headers);
183+
}
184+
172185
/**
173186
* Get the changes for a specific TV show id.
174187
*

lib/Tmdb/Repository/TvRepository.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,22 @@ public function getVideos($id, array $parameters = [], array $headers = [])
227227
return $tv->getVideos();
228228
}
229229

230+
/**
231+
* Get the watch providers (by region) for a TV series.
232+
*
233+
* @param $id
234+
* @param $parameters
235+
* @param $headers
236+
* @return GenericCollection
237+
*/
238+
public function getWatchProviders($id, array $parameters = [], array $headers = [])
239+
{
240+
$data = $this->getApi()->getWatchProviders($id, $this->parseQueryParameters($parameters), $headers);
241+
$tv = $this->getFactory()->create(['watch/providers' => $data]);
242+
243+
return $tv->getWatchProviders();
244+
}
245+
230246
/**
231247
* Get the alternative titles for a specific show ID.
232248
*

test/Tmdb/Tests/Api/TvTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,17 @@ public function shouldGetContentRatings()
221221
$this->assertLastRequestIsWithPathAndMethod('/3/tv/' . self::TV_ID . '/content_ratings');
222222
}
223223

224+
/**
225+
* @test
226+
*/
227+
public function shouldGetWatchProviders()
228+
{
229+
$api = $this->getApiWithMockedHttpAdapter();
230+
231+
$api->getWatchProviders(self::TV_ID);
232+
$this->assertLastRequestIsWithPathAndMethod('/3/tv/' . self::TV_ID . '/watch/providers');
233+
}
234+
224235
protected function getApiClass()
225236
{
226237
return 'Tmdb\Api\Tv';

test/Tmdb/Tests/Factory/TvFactoryTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,37 @@ public function shouldBeFunctional()
128128

129129
$this->assertEquals('US', $usContentRating->getIso31661());
130130
$this->assertEquals('TV-MA', $usContentRating->getRating());
131+
132+
$this->assertInstanceOf('Tmdb\Model\Common\GenericCollection', $this->tv->getWatchProviders());
133+
$this->assertInstanceOf('Tmdb\Model\Watch\Providers', $this->tv->getWatchProviders()->get('US'));
134+
$this->assertInstanceOf('Tmdb\Model\Common\GenericCollection', $this->tv->getWatchProviders()->get('US')->getFlatrate());
135+
136+
$watchProviders = $this->tv->getWatchProviders();
137+
$this->assertEquals(46, count($watchProviders));
138+
foreach ($watchProviders as $countryCode => $countryWatchProviders) {
139+
$this->assertEquals($countryCode, $countryWatchProviders->getIso31661());
140+
$this->assertNotEmpty($countryWatchProviders->getLink());
141+
$this->assertInstanceOf('Tmdb\Model\Common\GenericCollection', $countryWatchProviders->getFlatrate());
142+
$this->assertInstanceOf('Tmdb\Model\Common\GenericCollection', $countryWatchProviders->getRent());
143+
$this->assertInstanceOf('Tmdb\Model\Common\GenericCollection', $countryWatchProviders->getBuy());
144+
145+
$watchProvidersByType = [
146+
'flatrate' => $countryWatchProviders->getFlatrate(),
147+
'rent' => $countryWatchProviders->getRent(),
148+
'buy' => $countryWatchProviders->getBuy(),
149+
];
150+
151+
foreach ($watchProvidersByType as $type => $typeWatchProviders) {
152+
foreach ($typeWatchProviders as $watchProvider) {
153+
$this->assertEquals($countryCode, $watchProvider->getIso31661());
154+
$this->assertTrue(is_int($watchProvider->getId()));
155+
$this->assertNotEmpty($watchProvider->getName());
156+
$this->assertNotEmpty($watchProvider->getLogoPath());
157+
$this->assertTrue(is_int($watchProvider->getDisplayPriority()));
158+
$this->assertEquals($type, $watchProvider->getType());
159+
}
160+
}
161+
}
131162
}
132163

133164
/**

test/Tmdb/Tests/Repository/TvRepositoryTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,17 @@ public function shouldGetVideos()
175175
$this->assertLastRequestIsWithPathAndMethod('/3/tv/' . self::TV_ID . '/videos');
176176
}
177177

178+
/**
179+
* @test
180+
*/
181+
public function shouldGetWatchProviders()
182+
{
183+
$repository = $this->getRepositoryWithMockedHttpAdapter();
184+
185+
$repository->getWatchProviders(self::TV_ID);
186+
$this->assertLastRequestIsWithPathAndMethod('/3/tv/' . self::TV_ID . '/watch/providers');
187+
}
188+
178189
/**
179190
* @test
180191
*/

0 commit comments

Comments
 (0)