Skip to content

Commit c295875

Browse files
committed
Added movie watch providers tests
1 parent 92ac3a6 commit c295875

6 files changed

Lines changed: 1884 additions & 1 deletion

File tree

lib/Tmdb/Api/Movies.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,19 @@ public function getVideos($movie_id, array $parameters = [], array $headers = []
296296
return $this->get('movie/' . $movie_id . '/videos', $parameters, $headers);
297297
}
298298

299+
/**
300+
* Get the watch providers (by region) for a specific movie id.
301+
*
302+
* @param $movie_id
303+
* @param array $parameters
304+
* @param array $headers
305+
* @return mixed
306+
*/
307+
public function getWatchProviders($movie_id, array $parameters = [], array $headers = [])
308+
{
309+
return $this->get('movie/' . $movie_id . '/watch/providers', $parameters, $headers);
310+
}
311+
299312
/**
300313
* Get the external ids that we have stored for a movie.
301314
*

lib/Tmdb/Repository/MovieRepository.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,22 @@ public function getVideos($id, array $parameters = [], array $headers = [])
455455
return $movie->getVideos();
456456
}
457457

458+
/**
459+
* Get the watch providers (by region) for a specific movie id.
460+
*
461+
* @param $id
462+
* @param $parameters
463+
* @param $headers
464+
* @return GenericCollection
465+
*/
466+
public function getWatchProviders($id, array $parameters = [], array $headers = [])
467+
{
468+
$data = $this->getApi()->getWatchProviders($id, $this->parseQueryParameters($parameters), $headers);
469+
$movie = $this->getFactory()->create(['watch/providers' => $data]);
470+
471+
return $movie->getWatchProviders();
472+
}
473+
458474
/**
459475
* Get the external ids that we have stored for a movie.
460476
*

test/Tmdb/Tests/Api/MoviesTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,17 @@ public function shouldGetVideos()
254254
$this->assertLastRequestIsWithPathAndMethod('/3/movie/' . self::MOVIE_ID . '/videos');
255255
}
256256

257+
/**
258+
* @test
259+
*/
260+
public function shouldGetWatchProviders()
261+
{
262+
$api = $this->getApiWithMockedHttpAdapter();
263+
264+
$api->getWatchProviders(self::MOVIE_ID);
265+
$this->assertLastRequestIsWithPathAndMethod('/3/movie/' . self::MOVIE_ID . '/watch/providers');
266+
}
267+
257268
protected function getApiClass()
258269
{
259270
return 'Tmdb\Api\Movies';

test/Tmdb/Tests/Factory/MovieFactoryTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ public function shouldBeFunctional()
111111
$this->assertInstanceOf('Tmdb\Model\Common\GenericCollection', $this->movie->getSimilar());
112112
$this->assertInstanceOf('Tmdb\Model\Common\GenericCollection', $this->movie->getRecommendations());
113113
$this->assertInstanceOf('Tmdb\Model\Collection\Videos', $this->movie->getVideos());
114+
$this->assertInstanceOf('Tmdb\Model\Common\GenericCollection', $this->movie->getWatchProviders());
115+
$this->assertInstanceOf('Tmdb\Model\Watch\Providers', $this->movie->getWatchProviders()->get('US'));
116+
$this->assertInstanceOf('Tmdb\Model\Common\GenericCollection', $this->movie->getWatchProviders()->get('US')->getFlatrate());
114117

115118
/** @var Release[] $releases */
116119
$releases = $this->movie->getReleases()->getAll();
@@ -125,6 +128,33 @@ public function shouldBeFunctional()
125128
$this->assertInstanceOf(\DateTime::class, $release_date->getReleaseDate());
126129
$this->assertTrue(is_int($release_date->getType()));
127130
}
131+
132+
$watchProviders = $this->movie->getWatchProviders();
133+
$this->assertEquals(38, count($watchProviders));
134+
foreach ($watchProviders as $countryCode => $countryWatchProviders) {
135+
$this->assertEquals($countryCode, $countryWatchProviders->getIso31661());
136+
$this->assertNotEmpty($countryWatchProviders->getLink());
137+
$this->assertInstanceOf('Tmdb\Model\Common\GenericCollection', $countryWatchProviders->getFlatrate());
138+
$this->assertInstanceOf('Tmdb\Model\Common\GenericCollection', $countryWatchProviders->getRent());
139+
$this->assertInstanceOf('Tmdb\Model\Common\GenericCollection', $countryWatchProviders->getBuy());
140+
141+
$watchProvidersByType = [
142+
'flatrate' => $countryWatchProviders->getFlatrate(),
143+
'rent' => $countryWatchProviders->getRent(),
144+
'buy' => $countryWatchProviders->getBuy(),
145+
];
146+
147+
foreach ($watchProvidersByType as $type => $typeWatchProviders) {
148+
foreach ($typeWatchProviders as $watchProvider) {
149+
$this->assertEquals($countryCode, $watchProvider->getIso31661());
150+
$this->assertTrue(is_int($watchProvider->getId()));
151+
$this->assertNotEmpty($watchProvider->getName());
152+
$this->assertNotEmpty($watchProvider->getLogoPath());
153+
$this->assertTrue(is_int($watchProvider->getDisplayPriority()));
154+
$this->assertEquals($type, $watchProvider->getType());
155+
}
156+
}
157+
}
128158
}
129159

130160
/**

test/Tmdb/Tests/Repository/MovieRepositoryTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,17 @@ public function shouldGetVideos()
257257
$this->assertLastRequestIsWithPathAndMethod('/3/movie/' . self::MOVIE_ID . '/videos');
258258
}
259259

260+
/**
261+
* @test
262+
*/
263+
public function shouldGetWatchProviders()
264+
{
265+
$repository = $this->getRepositoryWithMockedHttpAdapter();
266+
267+
$repository->getWatchProviders(self::MOVIE_ID);
268+
$this->assertLastRequestIsWithPathAndMethod('/3/movie/' . self::MOVIE_ID . '/watch/providers');
269+
}
270+
260271
/**
261272
* @test
262273
*/

0 commit comments

Comments
 (0)