Skip to content

Commit

Permalink
Unit tests for Lists
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfzdotnet committed Feb 22, 2014
1 parent 8df2440 commit bc1e845
Show file tree
Hide file tree
Showing 3 changed files with 1,118 additions and 6 deletions.
9 changes: 3 additions & 6 deletions lib/Tmdb/Factory/ListFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use Tmdb\Factory\Lists\ListItemFactory;
use Tmdb\Model\Collection\Genres;
use Tmdb\Model\Common\GenericCollection;
use Tmdb\Model\Genre;
use Tmdb\Model\Lists;
use Tmdb\Model\Movie;
Expand Down Expand Up @@ -77,14 +78,10 @@ public function createItemStatus(array $data = array())
*/
public function createCollection(array $data = array())
{
$collection = new Genres();

if (array_key_exists('genres', $data)) {
$data = $data['genres'];
}
$collection = new GenericCollection();

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

return $collection;
Expand Down
83 changes: 83 additions & 0 deletions test/Tmdb/Tests/Factory/ListFactoryTest.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\Factory;

use Tmdb\Factory\ListFactory;
use Tmdb\Model\Lists;

class ListFactoryTest extends TestCase
{
private $data;

/**
* @var Lists
*/
private $lists;

public function setUp()
{
$this->data = $this->loadByFile('lists/get.json');

/**
* @var ListFactory $factory
*/
$factory = $this->getFactory();

/**
* @var Lists $list
*/
$this->lists = $factory->create($this->data);
}

/**
* @test
*/
public function shouldBeAbleToSetFactories()
{
/**
* @var ListFactory $factory
*/
$factory = $this->getFactory();

$class = new \stdClass();

$factory->setImageFactory($class);
$factory->setListItemFactory($class);

$this->assertInstanceOf('stdClass', $factory->getImageFactory());
$this->assertInstanceOf('stdClass', $factory->getListItemFactory());
}

/**
* @test
*/
public function shouldBeFunctional()
{
$this->assertEquals('Travis Bell', $this->lists->getCreatedBy());
$this->assertEquals('Here\'s my list of best picture winners for the Oscars. Thought it would be neat to see them all together. There\'s a lot of movies here I have never even heard of.', $this->lists->getDescription());
$this->assertEquals(18, $this->lists->getFavoriteCount());
$this->assertEquals('509ec17b19c2950a0600050d', $this->lists->getId());
$this->assertInstanceOf('Tmdb\Model\Common\GenericCollection', $this->lists->getItems());
$this->assertEquals(85, $this->lists->getItemCount());
$this->assertEquals('en', $this->lists->getIso6391());
$this->assertEquals('Best Picture Winners - The Academy Awards', $this->lists->getName());
$this->assertEquals('/efBm2Nm2v5kQnO0w3hYcW6hVsJU.jpg', $this->lists->getPosterPath());
$this->assertInstanceOf('Tmdb\Model\Image\PosterImage', $this->lists->getPosterImage());

}

protected function getFactoryClass()
{
return 'Tmdb\Factory\ListFactory';
}
}
Loading

0 comments on commit bc1e845

Please sign in to comment.