Skip to content

Commit

Permalink
Updating tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfzdotnet committed Jan 27, 2014
1 parent 5a7be3a commit 21ef258
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 14 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($item));
$collection->add(null, $this->create((array) $item));
}

return $collection;
Expand Down
27 changes: 20 additions & 7 deletions test/Tmdb/Tests/Factory/GenreFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,35 @@
*/
namespace Tmdb\Tests\Factory;

use Tmdb\Factory\GenreFactory;

class GenreFactoryTest extends TestCase
{
const GENRE_ID = 28;

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

$collection = $factory->createCollection($data['genres']);

$this->assertInstanceOf('Tmdb\Model\Collection\Genres', $collection);

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

$this->assertInstanceOf('Tmdb\Model\Genre', $object);
$this->assertEquals('28', $object->getId());
$this->assertEquals('Action', $object->getName());
// @todo actually get the first
foreach($filteredGenres as $filteredGenre) {
$this->assertInstanceOf('Tmdb\Model\Genre', $filteredGenre);
}
}

protected function getFactory()
{
return new GenreFactory();
}

protected function getFactoryClass()
Expand Down
20 changes: 14 additions & 6 deletions test/Tmdb/Tests/Factory/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,21 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase

protected function loadByFile($file)
{
$class = $this->getFactoryClass();
$factory = new $class();

//$data = json_decode(file_get_contents($file));
$data = array();
return json_decode(
file_get_contents(
sprintf(
'%s/%s',
'test/Tmdb/Tests/Resources/',
$file
)
)
);
}

return $factory->create($data);
protected function getFactory()
{
$class = $this->getFactoryClass();
return new $class();
}

abstract protected function getFactoryClass();
Expand Down
1 change: 1 addition & 0 deletions test/Tmdb/Tests/Resources/genre/result.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"genres":[{"id":28,"name":"Action"},{"id":12,"name":"Adventure"},{"id":16,"name":"Animation"},{"id":35,"name":"Comedy"},{"id":80,"name":"Crime"},{"id":105,"name":"Disaster"},{"id":99,"name":"Documentary"},{"id":18,"name":"Drama"},{"id":82,"name":"Eastern"},{"id":2916,"name":"Erotic"},{"id":10751,"name":"Family"},{"id":10750,"name":"Fan Film"},{"id":14,"name":"Fantasy"},{"id":10753,"name":"Film Noir"},{"id":10769,"name":"Foreign"},{"id":36,"name":"History"},{"id":10595,"name":"Holiday"},{"id":27,"name":"Horror"},{"id":10756,"name":"Indie"},{"id":10402,"name":"Music"},{"id":22,"name":"Musical"},{"id":9648,"name":"Mystery"},{"id":10754,"name":"Neo-noir"},{"id":1115,"name":"Road Movie"},{"id":10749,"name":"Romance"},{"id":878,"name":"Science Fiction"},{"id":10755,"name":"Short"},{"id":9805,"name":"Sport"},{"id":10758,"name":"Sporting Event"},{"id":10757,"name":"Sports Film"},{"id":10748,"name":"Suspense"},{"id":10770,"name":"TV movie"},{"id":53,"name":"Thriller"},{"id":10752,"name":"War"},{"id":37,"name":"Western"}]}

0 comments on commit 21ef258

Please sign in to comment.