1<?php 2/** 3 * This file is part of the Tmdb PHP API created by Michael Roterman. 4 * 5 * For the full copyright and license information, please view the LICENSE 6 * file that was distributed with this source code. 7 * 8 * @package Tmdb 9 * @author Michael Roterman <michael@wtfz.net> 10 * @copyright (c) 2013, Michael Roterman 11 * @version 0.0.1 12 */ 13namespace Tmdb\Tests\Repository; 14 15use Tmdb\Repository\MovieRepository; 16 17class MovieRepositoryTest extends TestCase 18{ 19 const MOVIE_ID = 120; 20 21 /** 22 * @test 23 */ 24 public function shouldLoadMovie() 25 { 26 $repository = $this->getRepositoryWithMockedHttpAdapter(); 27 28 $this->getAdapter()->expects($this->once()) 29 ->method('get') 30 ->with($this->getRequest( 31 'https://api.themoviedb.org/3/movie/' . self::MOVIE_ID, 32 ['append_to_response' => 'alternative_titles,changes,credits,images,keywords,lists,release_dates,reviews,similar,recommendations,translations,videos'] 33 )) 34 ; 35 36 $repository->load(self::MOVIE_ID); 37 } 38 39 /** 40 * @test 41 */ 42 public function shouldGetAlternativeTitles() 43 { 44 $repository = $this->getRepositoryWithMockedHttpAdapter(); 45 46 $this->getAdapter()->expects($this->once()) 47 ->method('get') 48 ->with($this->getRequest('https://api.themoviedb.org/3/movie/' . self::MOVIE_ID . '/alternative_titles')) 49 ; 50 51 $repository->getAlternativeTitles(self::MOVIE_ID); 52 } 53 54 /** 55 * @test 56 */ 57 public function shouldGetCredits() 58 { 59 $repository = $this->getRepositoryWithMockedHttpAdapter(); 60 61 $this->getAdapter()->expects($this->once()) 62 ->method('get') 63 ->with($this->getRequest('https://api.themoviedb.org/3/movie/' . self::MOVIE_ID . '/credits')) 64 ; 65 66 $repository->getCredits(self::MOVIE_ID); 67 } 68 69 /** 70 * @test 71 */ 72 public function shouldGetImages() 73 { 74 $repository = $this->getRepositoryWithMockedHttpAdapter(); 75 76 $this->getAdapter()->expects($this->once()) 77 ->method('get') 78 ->with($this->getRequest('https://api.themoviedb.org/3/movie/' . self::MOVIE_ID . '/images')) 79 ; 80 $repository->getImages(self::MOVIE_ID); 81 } 82 83 /** 84 * @test 85 */ 86 public function shouldGetKeywords() 87 { 88 $repository = $this->getRepositoryWithMockedHttpAdapter(); 89 90 $this->getAdapter()->expects($this->once()) 91 ->method('get') 92 ->with($this->getRequest('https://api.themoviedb.org/3/movie/' . self::MOVIE_ID . '/keywords')) 93 ; 94 95 $repository->getKeywords(self::MOVIE_ID); 96 } 97 98 /** 99 * @test 100 */ 101 public function shouldGetReleases() 102 { 103 $repository = $this->getRepositoryWithMockedHttpAdapter(); 104 105 $this->getAdapter()->expects($this->once()) 106 ->method('get') 107 ->with($this->getRequest('https://api.themoviedb.org/3/movie/' . self::MOVIE_ID . '/releases')) 108 ; 109 110 $repository->getReleases(self::MOVIE_ID); 111 } 112 113 /** 114 * @test 115 */ 116 public function shouldGetTranslations() 117 { 118 $repository = $this->getRepositoryWithMockedHttpAdapter(); 119 120 $this->getAdapter()->expects($this->once()) 121 ->method('get') 122 ->with($this->getRequest('https://api.themoviedb.org/3/movie/' . self::MOVIE_ID . '/translations')) 123 ; 124 125 $repository->getTranslations(self::MOVIE_ID); 126 } 127 128 /** 129 * @test 130 */ 131 public function shouldGetSimilar() 132 { 133 $repository = $this->getRepositoryWithMockedHttpAdapter(); 134 135 $this->getAdapter()->expects($this->once()) 136 ->method('get') 137 ->with($this->getRequest('https://api.themoviedb.org/3/movie/' . self::MOVIE_ID . '/similar')) 138 ; 139 140 $repository->getSimilar(self::MOVIE_ID); 141 } 142 143 /** 144 * @test 145 */ 146 public function shouldGetRecommended() 147 { 148 $repository = $this->getRepositoryWithMockedHttpAdapter(); 149 150 $this->getAdapter()->expects($this->once()) 151 ->method('get') 152 ->with($this->getRequest('https://api.themoviedb.org/3/movie/' . self::MOVIE_ID . '/recommendations')) 153 ; 154 155 $repository->getRecommendations(self::MOVIE_ID); 156 } 157 158 /** 159 * @test 160 */ 161 public function shouldGetReviews() 162 { 163 $repository = $this->getRepositoryWithMockedHttpAdapter(); 164 165 $this->getAdapter()->expects($this->once()) 166 ->method('get') 167 ->with($this->getRequest('https://api.themoviedb.org/3/movie/' . self::MOVIE_ID . '/reviews')) 168 ; 169 170 $repository->getReviews(self::MOVIE_ID); 171 } 172 173 /** 174 * @test 175 */ 176 public function shouldGetLists() 177 { 178 $repository = $this->getRepositoryWithMockedHttpAdapter(); 179 180 $this->getAdapter()->expects($this->once()) 181 ->method('get') 182 ->with($this->getRequest('https://api.themoviedb.org/3/movie/' . self::MOVIE_ID . '/lists')) 183 ; 184 185 $repository->getLists(self::MOVIE_ID); 186 } 187 188 /** 189 * @test 190 */ 191 public function shouldGetChanges() 192 { 193 $repository = $this->getRepositoryWithMockedHttpAdapter(); 194 195 $this->getAdapter()->expects($this->once()) 196 ->method('get') 197 ->with($this->getRequest('https://api.themoviedb.org/3/movie/' . self::MOVIE_ID . '/changes')) 198 ; 199 200 $repository->getChanges(self::MOVIE_ID); 201 } 202 203 /** 204 * @test 205 */ 206 public function shouldGetLatestMovie() 207 { 208 $repository = $this->getRepositoryWithMockedHttpAdapter(); 209 210 $this->getAdapter()->expects($this->once()) 211 ->method('get') 212 ->with($this->getRequest('https://api.themoviedb.org/3/movie/latest')) 213 ; 214 215 $repository->getLatest(); 216 } 217 218 /** 219 * @test 220 */ 221 public function shouldGetUpcoming() 222 { 223 $repository = $this->getRepositoryWithMockedHttpAdapter(); 224 225 $this->getAdapter()->expects($this->once()) 226 ->method('get') 227 ->with($this->getRequest('https://api.themoviedb.org/3/movie/upcoming')) 228 ; 229 230 $repository->getUpcoming(); 231 } 232 233 /** 234 * @test 235 */ 236 public function shouldGetNowPlaying() 237 { 238 $repository = $this->getRepositoryWithMockedHttpAdapter(); 239 240 $this->getAdapter()->expects($this->once()) 241 ->method('get') 242 ->with($this->getRequest('https://api.themoviedb.org/3/movie/now_playing')) 243 ; 244 245 $repository->getNowPlaying(); 246 } 247 248 /** 249 * @test 250 */ 251 public function shouldGetPopular() 252 { 253 $repository = $this->getRepositoryWithMockedHttpAdapter(); 254 255 $this->getAdapter()->expects($this->once()) 256 ->method('get') 257 ->with($this->getRequest('https://api.themoviedb.org/3/movie/popular')) 258 ; 259 260 $repository->getPopular(); 261 } 262 263 /** 264 * @test 265 */ 266 public function shouldGetTopRated() 267 { 268 $repository = $this->getRepositoryWithMockedHttpAdapter(); 269 270 $this->getAdapter()->expects($this->once()) 271 ->method('get') 272 ->with($this->getRequest('https://api.themoviedb.org/3/movie/top_rated')) 273 ; 274 275 $repository->getTopRated(); 276 } 277 278 /** 279 * @test 280 */ 281 public function shouldGetAccountStates() 282 { 283 $repository = $this->getRepositoryWithMockedHttpAdapter(); 284 285 $this->getAdapter()->expects($this->once()) 286 ->method('get') 287 ->with($this->getRequest('https://api.themoviedb.org/3/movie/id/account_states')) 288 ; 289 290 $repository->getAccountStates('id'); 291 } 292 293 /** 294 * @test 295 */ 296 public function shouldRate() 297 { 298 $repository = $this->getRepositoryWithMockedHttpAdapter(); 299 300 $this->getAdapter()->expects($this->once()) 301 ->method('post') 302 ->with($this->getRequest( 303 'https://api.themoviedb.org/3/movie/id/rating', 304 [], 305 'POST', 306 [], 307 ['value' => 5.2] 308 )) 309 ; 310 311 $repository->rate('id', 5.2); 312 } 313 314 /** 315 * @test 316 */ 317 public function shouldGetVideos() 318 { 319 $repository = $this->getRepositoryWithMockedHttpAdapter(); 320 321 $this->getAdapter()->expects($this->once()) 322 ->method('get') 323 ->with($this->getRequest('https://api.themoviedb.org/3/movie/' . self::MOVIE_ID . '/videos')) 324 ; 325 326 $repository->getVideos(self::MOVIE_ID); 327 } 328 329 /** 330 * @test 331 */ 332 public function shouldBeAbleToSetFactories() 333 { 334 /** 335 * @var MovieRepository $repository 336 */ 337 $repository = $this->getRepositoryWithMockedHttpClient(); 338 $class = new \stdClass(); 339 340 $repository->setAlternativeTitleFactory($class); 341 $repository->setImageFactory($class); 342 $repository->setPeopleFactory($class); 343 344 $this->assertInstanceOf('stdClass', $repository->getAlternativeTitleFactory()); 345 $this->assertInstanceOf('stdClass', $repository->getImageFactory()); 346 $this->assertInstanceOf('stdClass', $repository->getPeopleFactory()); 347 } 348 349 protected function getApiClass() 350 { 351 return 'Tmdb\Api\Movies'; 352 } 353 354 protected function getRepositoryClass() 355 { 356 return 'Tmdb\Repository\MovieRepository'; 357 } 358} 359