Skip to content

Commit

Permalink
Unit tests for Keyword, and removing unneccasary Movie/Keyword ( upda…
Browse files Browse the repository at this point in the history
…ted MovieFactory to reflect this ).
  • Loading branch information
wtfzdotnet committed Feb 22, 2014
1 parent 5b21bf5 commit 849d9e5
Show file tree
Hide file tree
Showing 8 changed files with 285 additions and 75 deletions.
10 changes: 0 additions & 10 deletions lib/Tmdb/Factory/KeywordFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,6 @@ public function create(array $data = array())
return $this->hydrate(new Keyword(), $data);
}

/**
* @param array $data
*
* @return Movie
*/
public function createMovie(array $data = array())
{
return $this->hydrate(new Movie(), $data);
}

/**
* {@inheritdoc}
*/
Expand Down
26 changes: 25 additions & 1 deletion lib/Tmdb/Factory/MovieFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ class MovieFactory extends AbstractFactory {
*/
private $listItemFactory;

/**
* @var KeywordFactory
*/
private $keywordFactory;

/**
* Constructor
*/
Expand All @@ -70,6 +75,7 @@ public function __construct()
$this->changeFactory = new ChangeFactory();
$this->reviewFactory = new ReviewFactory();
$this->listItemFactory = new ListItemFactory();
$this->keywordFactory = new KeywordFactory();
}

/**
Expand Down Expand Up @@ -120,7 +126,7 @@ public function create(array $data = array())

/** Keywords */
if (array_key_exists('keywords', $data)) {
$movie->setKeywords($this->createGenericCollection($data['keywords']['keywords'], new Movie\Keyword()));
$movie->setKeywords($this->getKeywordFactory()->createCollection($data['keywords']));
}

if (array_key_exists('releases', $data)) {
Expand Down Expand Up @@ -300,4 +306,22 @@ public function getListItemFactory()
{
return $this->listItemFactory;
}

/**
* @param \Tmdb\Factory\KeywordFactory $keywordFactory
* @return $this
*/
public function setKeywordFactory($keywordFactory)
{
$this->keywordFactory = $keywordFactory;
return $this;
}

/**
* @return \Tmdb\Factory\KeywordFactory
*/
public function getKeywordFactory()
{
return $this->keywordFactory;
}
}
2 changes: 1 addition & 1 deletion lib/Tmdb/Model/Collection/Keywords.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
namespace Tmdb\Model\Collection;

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

class Keywords extends GenericCollection {

Expand Down
62 changes: 0 additions & 62 deletions lib/Tmdb/Model/Movie/Keyword.php

This file was deleted.

46 changes: 46 additions & 0 deletions test/Tmdb/Tests/Factory/KeywordFactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?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\KeywordFactory;

class KeywordFactoryTest extends TestCase
{
private $data;

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

/**
* @test
*/
public function shouldConstructKeyword()
{
/**
* @var KeywordFactory $factory
*/
$factory = $this->getFactory();
$keyword = $factory->create($this->data);

$this->assertInstanceOf('Tmdb\Model\Keyword', $keyword);
$this->assertEquals(1721, $keyword->getId());
$this->assertEquals('fight', $keyword->getName());
}

protected function getFactoryClass()
{
return 'Tmdb\Factory\KeywordFactory';
}
}
2 changes: 1 addition & 1 deletion test/Tmdb/Tests/Model/Collection/KeywordsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
namespace Tmdb\Tests\Model\Common;

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

class KeywordsTest extends TestCase
Expand Down
4 changes: 4 additions & 0 deletions test/Tmdb/Tests/Resources/keywords/get.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"id": 1721,
"name": "fight"
}
Loading

0 comments on commit 849d9e5

Please sign in to comment.