diff --git a/lib/Tmdb/Repository/CompanyRepository.php b/lib/Tmdb/Repository/CompanyRepository.php index ab06c371..f8e15ed6 100644 --- a/lib/Tmdb/Repository/CompanyRepository.php +++ b/lib/Tmdb/Repository/CompanyRepository.php @@ -67,6 +67,14 @@ public function getFactory() return new CompanyFactory(); } + /** + * @return MovieFactory + */ + public function getMovieFactory() + { + return new MovieFactory(); + } + /** * Create an collection of an array * @@ -81,7 +89,7 @@ private function createMovieCollection($data){ } foreach($data as $item) { - $collection->add(null, MovieFactory::create($item)); + $collection->add(null, $this->getMovieFactory()->create($item)); } return $collection; diff --git a/lib/Tmdb/Repository/TvEpisodeRepository.php b/lib/Tmdb/Repository/TvEpisodeRepository.php index 278f8a3b..ec287f9c 100644 --- a/lib/Tmdb/Repository/TvEpisodeRepository.php +++ b/lib/Tmdb/Repository/TvEpisodeRepository.php @@ -12,9 +12,8 @@ */ namespace Tmdb\Repository; -use \RuntimeException; +use Tmdb\Exception\RuntimeException; use Tmdb\Factory\TvEpisodeFactory; -use Tmdb\Model\Common\GenericCollection; use Tmdb\Model\Tv\Episode\QueryParameter\AppendToResponse; use Tmdb\Model\Tv; use Tmdb\Model\Tv\Season; @@ -85,24 +84,4 @@ public function getFactory() { return new TvEpisodeFactory(); } - - /** - * Create an collection of an array - * - * @param $data - * @return Episode[] - */ - private function createCollection($data){ - $collection = new GenericCollection(); - - if (array_key_exists('results', $data)) { - $data = $data['results']; - } - - foreach($data as $item) { - $collection->add(null, $this->getFactory()->create($item)); - } - - return $collection; - } } diff --git a/lib/Tmdb/Repository/TvRepository.php b/lib/Tmdb/Repository/TvRepository.php index 88126c4e..10084831 100644 --- a/lib/Tmdb/Repository/TvRepository.php +++ b/lib/Tmdb/Repository/TvRepository.php @@ -108,7 +108,7 @@ private function createCollection($data){ } foreach($data as $item) { - $collection->add(null, TvFactory::create($item)); + $collection->add(null, $this->getFactory()->create($item)); } return $collection; diff --git a/lib/Tmdb/Repository/TvSeasonRepository.php b/lib/Tmdb/Repository/TvSeasonRepository.php index 359267eb..563a195a 100644 --- a/lib/Tmdb/Repository/TvSeasonRepository.php +++ b/lib/Tmdb/Repository/TvSeasonRepository.php @@ -12,10 +12,9 @@ */ namespace Tmdb\Repository; -use \RuntimeException; +use Tmdb\Exception\RuntimeException; use Tmdb\Factory\TvSeasonFactory; -use Tmdb\Model\Common\GenericCollection; use \Tmdb\Model\Tv\Season\QueryParameter\AppendToResponse; use Tmdb\Model\Tv\Season; @@ -81,26 +80,4 @@ public function getFactory() { return new TvSeasonFactory(); } - - /** - * Create an collection of an array - * - * @todo Allow an array of Season objects to pass ( custom collection ) - * - * @param $data - * @return Season[] - */ - private function createCollection($data){ - $collection = new GenericCollection(); - - if (array_key_exists('results', $data)) { - $data = $data['results']; - } - - foreach($data as $item) { - $collection->add(null, $this->getFactory()->create($item)); - } - - return $collection; - } } diff --git a/test/Tmdb/Tests/Factory/GenreFactoryTest.php b/test/Tmdb/Tests/Factory/GenreFactoryTest.php new file mode 100644 index 00000000..ec4cc46c --- /dev/null +++ b/test/Tmdb/Tests/Factory/GenreFactoryTest.php @@ -0,0 +1,37 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Tests\Factory; + +class GenreFactoryTest extends TestCase +{ + const GENRE_ID = 28; + + /** + * @test + */ + public function shouldConstructGenre() + { + $object = $this->loadByFile( + 'file.json' + ); + + $this->assertInstanceOf('Tmdb\Model\Genre', $object); + $this->assertEquals('28', $object->getId()); + $this->assertEquals('Action', $object->getName()); + } + + protected function getFactoryClass() + { + return 'Tmdb\Factory\GenreFactory'; + } +} \ No newline at end of file diff --git a/test/Tmdb/Tests/Factory/TestCase.php b/test/Tmdb/Tests/Factory/TestCase.php new file mode 100644 index 00000000..a59d7c0e --- /dev/null +++ b/test/Tmdb/Tests/Factory/TestCase.php @@ -0,0 +1,31 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Tests\Factory; + +abstract class TestCase extends \PHPUnit_Framework_TestCase +{ + protected $factory; + + protected function loadByFile($file) + { + $class = $this->getFactoryClass(); + $factory = new $class(); + + //$data = json_decode(file_get_contents($file)); + $data = array(); + + return $factory->create($data); + } + + abstract protected function getFactoryClass(); +} diff --git a/test/Tmdb/Tests/Repository/ChangesRepositoryTest.php b/test/Tmdb/Tests/Repository/ChangesRepositoryTest.php new file mode 100644 index 00000000..e4d86259 --- /dev/null +++ b/test/Tmdb/Tests/Repository/ChangesRepositoryTest.php @@ -0,0 +1,64 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Tests\Repository; + +use Tmdb\Model\Query\ChangesQuery; + +class ChangesRepositoryTest extends TestCase +{ + /** + * @test + */ + public function shouldGetMovieChanges() + { + $repository = $this->getRepositoryWithMockedHttpClient(); + + $query = new ChangesQuery(); + + $repository->getMovieChanges($query); + } + + /** + * @test + */ + public function shouldGetPeopleChanges() + { + $repository = $this->getRepositoryWithMockedHttpClient(); + + $query = new ChangesQuery(); + + $repository->getPeopleChanges($query); + } + + /** + * There is no generic factory for changes so it should never be called. + * + * @expectedException Tmdb\Exception\NotImplementedException + * @test + */ + public function getFactoryShouldThrowException() + { + $repository = $this->getRepositoryWithMockedHttpClient(); + $repository->getFactory(); + } + + protected function getApiClass() + { + return 'Tmdb\Api\Changes'; + } + + protected function getRepositoryClass() + { + return 'Tmdb\Repository\ChangesRepository'; + } +} \ No newline at end of file diff --git a/test/Tmdb/Tests/Repository/CompanyRepositoryTest.php b/test/Tmdb/Tests/Repository/CompanyRepositoryTest.php index 0c00f917..d3ade661 100644 --- a/test/Tmdb/Tests/Repository/CompanyRepositoryTest.php +++ b/test/Tmdb/Tests/Repository/CompanyRepositoryTest.php @@ -26,6 +26,17 @@ public function shouldLoadCompany() $repository->load(self::COMPANY_ID); } + /** + * @test + */ + public function shouldGetMovies() + { + $repository = $this->getRepositoryWithMockedHttpClient(); + + $repository->getMovies(self::COMPANY_ID); + } + + protected function getApiClass() { return 'Tmdb\Api\Company'; diff --git a/test/Tmdb/Tests/Repository/MovieRepositoryTest.php b/test/Tmdb/Tests/Repository/MovieRepositoryTest.php index 16f5ab52..f015ae9c 100644 --- a/test/Tmdb/Tests/Repository/MovieRepositoryTest.php +++ b/test/Tmdb/Tests/Repository/MovieRepositoryTest.php @@ -73,7 +73,7 @@ public function shouldGetTopRated() { $repository = $this->getRepositoryWithMockedHttpClient(); - $repository->getLatest(); + $repository->getTopRated(); } protected function getApiClass() diff --git a/test/Tmdb/Tests/Repository/TvEpisodeRepositoryTest.php b/test/Tmdb/Tests/Repository/TvEpisodeRepositoryTest.php index 91d1fb91..aa42b1d4 100644 --- a/test/Tmdb/Tests/Repository/TvEpisodeRepositoryTest.php +++ b/test/Tmdb/Tests/Repository/TvEpisodeRepositoryTest.php @@ -12,6 +12,10 @@ */ namespace Tmdb\Tests\Repository; +use Tmdb\Model\Tv\Episode; +use Tmdb\Model\Tv\Season; +use Tmdb\Model\Tv; + class TvEpisodeRepositoryTest extends TestCase { const TV_ID = 3572; @@ -28,6 +32,55 @@ public function shouldLoadTvEpisode() $repository->load(self::TV_ID, self::SEASON_ID, self::EPISODE_ID); } + /** + * @test + */ + public function shouldBeAbleToLoadTvSeasonWithTvAndSeason() + { + $repository = $this->getRepositoryWithMockedHttpClient(); + + $tv = new Tv(); + $tv->setId(self::TV_ID); + + $season = new Season(); + $season->setId(self::SEASON_ID); + + $episode = new Episode(); + $episode->setId(self::EPISODE_ID); + + $repository->load($tv, $season, $episode); + } + + /** + * @expectedException Tmdb\Exception\RuntimeException + * @test + */ + public function shouldThrowExceptionWhenConditionsNotMet() + { + $repository = $this->getRepositoryWithMockedHttpClient(); + + $tv = new Tv(); + $tv->setId(self::TV_ID); + + $season = new Season(); + $season->setId(self::SEASON_ID); + + $repository->load($tv, $season, null); + } + + + /** + * @expectedException Tmdb\Exception\RuntimeException + * @test + */ + public function shouldThrowExceptionWhenConditionsNotMetAll() + { + $repository = $this->getRepositoryWithMockedHttpClient(); + + $repository->load(null, null, null); + } + + protected function getApiClass() { return 'Tmdb\Api\TvEpisode'; diff --git a/test/Tmdb/Tests/Repository/TvRepositoryTest.php b/test/Tmdb/Tests/Repository/TvRepositoryTest.php index 3ee79ba8..a77cc3a2 100644 --- a/test/Tmdb/Tests/Repository/TvRepositoryTest.php +++ b/test/Tmdb/Tests/Repository/TvRepositoryTest.php @@ -26,6 +26,26 @@ public function shouldLoadTv() $repository->load(self::TV_ID); } + /** + * @test + */ + public function shouldGetPopular() + { + $repository = $this->getRepositoryWithMockedHttpClient(); + + $repository->getPopular(); + } + + /** + * @test + */ + public function shouldGetTopRated() + { + $repository = $this->getRepositoryWithMockedHttpClient(); + + $repository->getTopRated(); + } + protected function getApiClass() { return 'Tmdb\Api\Tv'; diff --git a/test/Tmdb/Tests/Repository/TvSeasonRepositoryTest.php b/test/Tmdb/Tests/Repository/TvSeasonRepositoryTest.php index ce41426a..6bcf3b4b 100644 --- a/test/Tmdb/Tests/Repository/TvSeasonRepositoryTest.php +++ b/test/Tmdb/Tests/Repository/TvSeasonRepositoryTest.php @@ -12,6 +12,8 @@ */ namespace Tmdb\Tests\Repository; +use Tmdb\Model\Tv; + class TvSeasonRepositoryTest extends TestCase { const TV_ID = 3572; @@ -27,6 +29,47 @@ public function shouldLoadTvSeason() $repository->load(self::TV_ID, self::SEASON_ID); } + /** + * @test + */ + public function shouldBeAbleToLoadTvSeasonWithTvAndSeason() + { + $repository = $this->getRepositoryWithMockedHttpClient(); + + $tv = new Tv(); + $tv->setId(self::TV_ID); + + $season = new Tv\Season(); + $season->setId(self::SEASON_ID); + + $repository->load($tv, $season); + } + + /** + * @expectedException Tmdb\Exception\RuntimeException + * @test + */ + public function shouldThrowExceptionWhenConditionsNotMet() + { + $repository = $this->getRepositoryWithMockedHttpClient(); + + $tv = new Tv(); + $tv->setId(self::TV_ID); + + $repository->load($tv, null); + } + + /** + * @expectedException Tmdb\Exception\RuntimeException + * @test + */ + public function shouldThrowExceptionWhenConditionsNotMetAll() + { + $repository = $this->getRepositoryWithMockedHttpClient(); + $repository->load(null, null); + } + + protected function getApiClass() { return 'Tmdb\Api\TvSeason'; diff --git a/test/Tmdb/Tests/Resources/genre/result.json b/test/Tmdb/Tests/Resources/genre/result.json new file mode 100644 index 00000000..e69de29b