Skip to content

Commit

Permalink
Updating MovieRepositoryTest and fixing some issues in MovieFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfzdotnet committed Feb 23, 2014
1 parent 3c11382 commit c1a2e68
Show file tree
Hide file tree
Showing 2 changed files with 137 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/Tmdb/Factory/MovieFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,23 +129,23 @@ public function create(array $data = array())
$movie->setKeywords($this->getKeywordFactory()->createCollection($data['keywords']));
}

if (array_key_exists('releases', $data)) {
if (array_key_exists('releases', $data) && array_key_exists('countries', $data['releases'])) {
$movie->setReleases($this->createGenericCollection($data['releases']['countries'], new Movie\Release()));
}

/**
* @TODO actually implement more providers? ( Can't seem to find any quicktime related trailers anyways? ). For now KISS
*/
if (array_key_exists('trailers', $data)) {
if (array_key_exists('trailers', $data) && array_key_exists('youtube', $data['trailers'])) {
$movie->setTrailers($this->createGenericCollection($data['trailers']['youtube'], new Youtube()));
}

if (array_key_exists('translations', $data)) {
if (array_key_exists('translations', $data) && array_key_exists('translations', $data['translations'])) {
$movie->setTranslations($this->createGenericCollection($data['translations']['translations'], new Translation()));
}

if (array_key_exists('similar_movies', $data)) {
$movie->setSimilarMovies($this->createCollection($data['similar_movies']['results']));
$movie->setSimilarMovies($this->createResultCollection($data['similar_movies']));
}

if (array_key_exists('reviews', $data)) {
Expand Down
133 changes: 133 additions & 0 deletions test/Tmdb/Tests/Repository/MovieRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
*/
namespace Tmdb\Tests\Repository;

use Tmdb\Repository\MovieRepository;

class MovieRepositoryTest extends TestCase
{
const MOVIE_ID = 120;
Expand All @@ -26,6 +28,117 @@ public function shouldLoadMovie()
$repository->load(self::MOVIE_ID);
}

/**
* @test
*/
public function shouldGetAlternativeTitles()
{
$repository = $this->getRepositoryWithMockedHttpClient();

$repository->getAlternativeTitles(self::MOVIE_ID);
}

/**
* @test
*/
public function shouldGetCredits()
{
$repository = $this->getRepositoryWithMockedHttpClient();

$repository->getCredits(self::MOVIE_ID);
}

/**
* @test
*/
public function shouldGetImages()
{
$repository = $this->getRepositoryWithMockedHttpClient();

$repository->getImages(self::MOVIE_ID);
}

/**
* @test
*/
public function shouldGetKeywords()
{
$repository = $this->getRepositoryWithMockedHttpClient();

$repository->getKeywords(self::MOVIE_ID);
}

/**
* @test
*/
public function shouldGetReleases()
{
$repository = $this->getRepositoryWithMockedHttpClient();

$repository->getReleases(self::MOVIE_ID);
}

/**
* @test
*/
public function shouldGetTrailers()
{
$repository = $this->getRepositoryWithMockedHttpClient();

$repository->getTrailers(self::MOVIE_ID);
}

/**
* @test
*/
public function shouldGetTranslations()
{
$repository = $this->getRepositoryWithMockedHttpClient();

$repository->getTranslations(self::MOVIE_ID);
}

/**
* @test
*/
public function shouldGetSimilarMovies()
{
$repository = $this->getRepositoryWithMockedHttpClient();

$repository->getSimilarMovies(self::MOVIE_ID);
}

/**
* @test
*/
public function shouldGetReviews()
{
$repository = $this->getRepositoryWithMockedHttpClient();

$repository->getReviews(self::MOVIE_ID);
}

/**
* @test
* @todo FIX
*/
public function shouldGetLists()
{
// $repository = $this->getRepositoryWithMockedHttpClient();
//
// $repository->getLists(self::MOVIE_ID);
}

/**
* @test
*/
public function shouldGetChanges()
{
$repository = $this->getRepositoryWithMockedHttpClient();

$repository->getChanges(self::MOVIE_ID);
}

/**
* @test
*/
Expand Down Expand Up @@ -76,6 +189,26 @@ public function shouldGetTopRated()
$repository->getTopRated();
}

/**
* @test
*/
public function shouldBeAbleToSetFactories()
{
/**
* @var MovieRepository $repository
*/
$repository = $this->getRepositoryWithMockedHttpClient();
$class = new \stdClass();

$repository->setAlternativeTitlesFactory($class);
$repository->setImagesFactory($class);
$repository->setPeopleFactory($class);

$this->assertInstanceOf('stdClass', $repository->getAlternativeTitlesFactory());
$this->assertInstanceOf('stdClass', $repository->getImagesFactory());
$this->assertInstanceOf('stdClass', $repository->getPeopleFactory());
}

protected function getApiClass()
{
return 'Tmdb\Api\Movies';
Expand Down

0 comments on commit c1a2e68

Please sign in to comment.