Skip to content

Commit

Permalink
Fixing up more unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfzdotnet committed Feb 2, 2014
1 parent f38feb6 commit c9c8e64
Show file tree
Hide file tree
Showing 9 changed files with 285 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/Tmdb/Factory/GenreFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function createCollection(array $data = array())
$collection = new Genres();

foreach($data as $item) {
$collection->add(null, $this->create((array) $item));
$collection->addGenre($this->create((array) $item));
}

return $collection;
Expand Down
2 changes: 1 addition & 1 deletion lib/Tmdb/Factory/ImageFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function createImageCollection(array $data = array())
if (array_key_exists($format, Image::$_formats)) {
$item = $this->create($item, $format);

$collection->add(null, $item);
$collection->addImage($item);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Tmdb/Model/Collection/Keywords.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
* @copyright (c) 2013, Michael Roterman
* @version 0.0.1
*/
namespace Tmdb\Model\Common\Collection;
namespace Tmdb\Model\Collection;

use Tmdb\Model\Common\GenericCollection;
use Tmdb\Model\Keyword;
use Tmdb\Model\Movie\Keyword;

class Keywords extends GenericCollection {

Expand Down
33 changes: 31 additions & 2 deletions test/Tmdb/Tests/Factory/GenreFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
*/
namespace Tmdb\Tests\Factory;

use Tmdb\Model\Collection\Genres;

class GenreFactoryTest extends TestCase
{
const GENRE_ID = 28;
Expand Down Expand Up @@ -46,14 +48,41 @@ public function shouldFilter()
$factory = $this->getFactory();
$data = $this->loadByFile('genre/result.json');

$collection = $factory->createCollection($data['genres']);
$filteredGenres = $collection->filterId(self::GENRE_ID);
/**
* @var Genres $genres
*/
$genres = $factory->createCollection($data['genres']);

$filteredGenres = $genres->filterId(self::GENRE_ID);

foreach($filteredGenres as $filteredGenre) {
$this->assertEquals('Action', $filteredGenre->getName());
}
}

/**
* @test
*/
public function shouldCollaborateWithCollection()
{
$factory = $this->getFactory();
$data = $this->loadByFile('genre/result.json');

/**
* @var Genres $genres
*/
$genres = $factory->createCollection($data['genres']);


$this->assertEquals(count($data['genres']), count($genres->getGenres()));

$genre = $genres->getGenre(28);
$this->assertEquals('Action', $genre->getName());

$genre = $genres->getGenre(-1);
$this->assertEquals(null, $genre);
}

protected function getFactoryClass()
{
return 'Tmdb\Factory\GenreFactory';
Expand Down
29 changes: 29 additions & 0 deletions test/Tmdb/Tests/Factory/ImageFactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/**
* This file is part of the Tmdb PHP API created by Michael Roterman.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @package Tmdb
* @author Michael Roterman <[email protected]>
* @copyright (c) 2013, Michael Roterman
* @version 0.0.1
*/
namespace Tmdb\Tests\Factory;

class ImageFactoryTest extends TestCase
{
/**
* @test
*/
public function shouldConstructGenres()
{
$this->assertEquals(true,true);
}

protected function getFactoryClass()
{
return 'Tmdb\Factory\ImageFactory';
}
}
34 changes: 34 additions & 0 deletions test/Tmdb/Tests/Factory/MovieFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,43 @@ public function shouldBeAbleToSetFactories()
$this->assertInstanceOf('stdClass', $factory->getImageFactory());
}

/**
* @test
*/
public function shouldBeFunctional()
{
$this->assertEquals(false, $this->movie->getAdult());
$this->assertEquals('/7DlIoyQ3ecGMklVWyKsneZmVnsi.jpg', $this->movie->getBackdropPath());
$this->assertInstanceOf('Tmdb\Model\Image\BackdropImage', $this->movie->getBackdrop());
$this->assertEquals(true, is_array($this->movie->getBelongsToCollection()));
$this->assertEquals(true, is_int($this->movie->getBudget()));
$this->assertInstanceOf('Tmdb\Model\Collection\Genres', $this->movie->getGenres());
$this->assertEquals('http://www.riddick-movie.com', $this->movie->getHomepage());
$this->assertEquals(87421, $this->movie->getId());
$this->assertEquals('Riddick', $this->movie->getOriginalTitle());
$this->assertEquals('Betrayed by his own kind and left for dead on a desolate planet, Riddick fights for survival against alien predators and becomes more powerful and dangerous than ever before. Soon bounty hunters from throughout the galaxy descend on Riddick only to find themselves pawns in his greater scheme for revenge. With his enemies right where he wants them, Riddick unleashes a vicious attack of vengeance before returning to his home planet of Furya to save it from destruction.', $this->movie->getOverview());
$this->assertEquals(93.491722439366, $this->movie->getPopularity());
$this->assertInstanceOf('Tmdb\Model\Image\PosterImage', $this->movie->getPoster());
$this->assertEquals('/1NfhdnQAEqcBRCulEhOFSkRrrLv.jpg', $this->movie->getPosterPath());
$this->assertInstanceOf('Tmdb\Model\Common\GenericCollection', $this->movie->getProductionCompanies());
$this->assertInstanceOf('Tmdb\Model\Common\GenericCollection', $this->movie->getProductionCountries());
// release
$this->assertEquals(42025135, $this->movie->getRevenue());
$this->assertEquals(119, $this->movie->getRuntime());
$this->assertInstanceOf('Tmdb\Model\Common\GenericCollection', $this->movie->getSpokenLanguages());
$this->assertEquals('Released', $this->movie->getStatus());
$this->assertEquals('Survival Is His Revenge', $this->movie->getTagline());
$this->assertEquals(6.2, $this->movie->getVoteAverage());
$this->assertEquals(625, $this->movie->getVoteCount());
$this->assertInstanceOf('Tmdb\Model\Common\GenericCollection', $this->movie->getAlternativeTitles());
$this->assertInstanceOf('Tmdb\Model\Common\GenericCollection', $this->movie->getChanges());
$this->assertInstanceOf('Tmdb\Model\Collection\Credits', $this->movie->getCredits());
$this->assertInstanceOf('Tmdb\Model\Collection\Images', $this->movie->getImages());
$this->assertInstanceOf('Tmdb\Model\Common\GenericCollection', $this->movie->getKeywords());
$this->assertInstanceOf('Tmdb\Model\Common\GenericCollection', $this->movie->getLists());
$this->assertInstanceOf('Tmdb\Model\Common\GenericCollection', $this->movie->getReleases());
$this->assertInstanceOf('Tmdb\Model\Common\GenericCollection', $this->movie->getSimilarMovies());
$this->assertInstanceOf('Tmdb\Model\Common\GenericCollection', $this->movie->getTrailers());
}

protected function getFactoryClass()
Expand Down
52 changes: 52 additions & 0 deletions test/Tmdb/Tests/Model/Collection/KeywordsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
/**
* This file is part of the Tmdb PHP API created by Michael Roterman.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @package Tmdb
* @author Michael Roterman <[email protected]>
* @copyright (c) 2013, Michael Roterman
* @version 0.0.1
*/
namespace Tmdb\Tests\Model\Common;

use Tmdb\Model\Collection\Keywords;
use Tmdb\Model\Movie\Keyword;
use Tmdb\Tests\Model\TestCase;

class KeywordsTest extends TestCase
{
/**
* @var Keywords
*/
private $collection;

private $keywords = array(
array('id' => 1, 'name' => 'dark'),
array('id' => 2, 'name' => 'light')
);

public function setUp()
{
$this->collection = new Keywords();

foreach($this->keywords as $keyword) {
$object = $this->hydrate(new Keyword(), $keyword);

$this->collection->addKeyword($object);
}
}

/**
* @test
*/
public function shouldGetAndSet()
{
$this->assertEquals(count($this->keywords), count($this->collection->getKeywords()));

$this->assertEquals('dark', $this->collection->getKeyword(1)->getName());
$this->assertEquals(null, $this->collection->getKeyword(3));
}
}
52 changes: 52 additions & 0 deletions test/Tmdb/Tests/Model/Collection/PeopleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
/**
* This file is part of the Tmdb PHP API created by Michael Roterman.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @package Tmdb
* @author Michael Roterman <[email protected]>
* @copyright (c) 2013, Michael Roterman
* @version 0.0.1
*/
namespace Tmdb\Tests\Model\Common;

use Tmdb\Model\Collection\People;
use Tmdb\Model\Person;
use Tmdb\Tests\Model\TestCase;

class PeopleTest extends TestCase
{
/**
* @var People
*/
private $collection;

private $people = array(
array('id' => 1, 'name' => 'james blunt'),
array('id' => 2, 'name' => 'afrojack')
);

public function setUp()
{
$this->collection = new People();

foreach($this->people as $keyword) {
$object = $this->hydrate(new Person(), $keyword);

$this->collection->addPerson($object);
}
}

/**
* @test
*/
public function shouldGetAndSet()
{
$this->assertEquals(count($this->people), count($this->collection->getPeople()));

$this->assertEquals('james blunt', $this->collection->getPerson(1)->getName());
$this->assertEquals(null, $this->collection->getPerson(3));
}
}
83 changes: 83 additions & 0 deletions test/Tmdb/Tests/Model/ImageTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php
/**
* This file is part of the Tmdb PHP API created by Michael Roterman.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @package Tmdb
* @author Michael Roterman <[email protected]>
* @copyright (c) 2013, Michael Roterman
* @version 0.0.1
*/
namespace Tmdb\Tests\Model;

use Tmdb\Factory\ImageFactory;
use Tmdb\Model\Collection\Images;
use Tmdb\Model\Image;

class ImageTest extends TestCase
{
/**
* @var Images
*/
private $collection;

private $images = array(
array(
'file_path' => '/abc.jpg',
'width' => 1000,
'height' => 750,
'iso_639_1' => 'en',
'aspect_ratio' => 0.75,
'vote_average' => 2.25,
'vote_count' => 25
),
);

public function setUp()
{
$this->collection = new Images();

foreach($this->images as $image) {
$factory = new ImageFactory();
$object = $factory->create($image);

$this->collection->addImage($object);
}
}

/**
* @test
*/
public function shouldGetAndSet()
{
$this->assertEquals(count($this->images), count($this->collection->getImages()));

/**
* @var Image $subject
*/
$subject = array_pop($this->collection->toArray());

$this->assertEquals('/abc.jpg', $subject->getFilePath());
$this->assertEquals(1000, $subject->getWidth());
$this->assertEquals(750, $subject->getHeight());
$this->assertEquals('en', $subject->getIso6391());
$this->assertEquals(0.75, $subject->getAspectRatio());
$this->assertEquals(2.25, $subject->getVoteAverage());
$this->assertEquals(25, $subject->getVoteCount());
}

/**
* @test
*/
public function shouldReturnCorrectTypes()
{
$this->assertEquals('poster', Image::getTypeFromCollectionName('posters'));
$this->assertEquals('backdrop', Image::getTypeFromCollectionName('backdrops'));
$this->assertEquals('profile', Image::getTypeFromCollectionName('profiles'));
$this->assertEquals('logo', Image::getTypeFromCollectionName('logos'));
$this->assertEquals('still', Image::getTypeFromCollectionName('stills'));
$this->assertEquals(null, Image::getTypeFromCollectionName('sheeps'));
}
}

0 comments on commit c9c8e64

Please sign in to comment.