From 849d9e50bc121fbead61f3a989eacdf937d8544e Mon Sep 17 00:00:00 2001 From: Michael Roterman Date: Sat, 22 Feb 2014 15:04:36 +0100 Subject: [PATCH] Unit tests for Keyword, and removing unneccasary Movie/Keyword ( updated MovieFactory to reflect this ). --- lib/Tmdb/Factory/KeywordFactory.php | 10 - lib/Tmdb/Factory/MovieFactory.php | 26 ++- lib/Tmdb/Model/Collection/Keywords.php | 2 +- lib/Tmdb/Model/Movie/Keyword.php | 62 ------ .../Tmdb/Tests/Factory/KeywordFactoryTest.php | 46 ++++ .../Tests/Model/Collection/KeywordsTest.php | 2 +- test/Tmdb/Tests/Resources/keywords/get.json | 4 + .../Tmdb/Tests/Resources/keywords/movies.json | 208 ++++++++++++++++++ 8 files changed, 285 insertions(+), 75 deletions(-) delete mode 100644 lib/Tmdb/Model/Movie/Keyword.php create mode 100644 test/Tmdb/Tests/Factory/KeywordFactoryTest.php create mode 100644 test/Tmdb/Tests/Resources/keywords/get.json create mode 100644 test/Tmdb/Tests/Resources/keywords/movies.json diff --git a/lib/Tmdb/Factory/KeywordFactory.php b/lib/Tmdb/Factory/KeywordFactory.php index c44dd148..2a6598e4 100644 --- a/lib/Tmdb/Factory/KeywordFactory.php +++ b/lib/Tmdb/Factory/KeywordFactory.php @@ -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} */ diff --git a/lib/Tmdb/Factory/MovieFactory.php b/lib/Tmdb/Factory/MovieFactory.php index 7c120c89..98aa4d6e 100644 --- a/lib/Tmdb/Factory/MovieFactory.php +++ b/lib/Tmdb/Factory/MovieFactory.php @@ -58,6 +58,11 @@ class MovieFactory extends AbstractFactory { */ private $listItemFactory; + /** + * @var KeywordFactory + */ + private $keywordFactory; + /** * Constructor */ @@ -70,6 +75,7 @@ public function __construct() $this->changeFactory = new ChangeFactory(); $this->reviewFactory = new ReviewFactory(); $this->listItemFactory = new ListItemFactory(); + $this->keywordFactory = new KeywordFactory(); } /** @@ -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)) { @@ -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; + } } \ No newline at end of file diff --git a/lib/Tmdb/Model/Collection/Keywords.php b/lib/Tmdb/Model/Collection/Keywords.php index 4977dfac..9f9f9146 100644 --- a/lib/Tmdb/Model/Collection/Keywords.php +++ b/lib/Tmdb/Model/Collection/Keywords.php @@ -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 { diff --git a/lib/Tmdb/Model/Movie/Keyword.php b/lib/Tmdb/Model/Movie/Keyword.php deleted file mode 100644 index 7b7fcabf..00000000 --- a/lib/Tmdb/Model/Movie/Keyword.php +++ /dev/null @@ -1,62 +0,0 @@ - - * @copyright (c) 2013, Michael Roterman - * @version 0.0.1 - */ -namespace Tmdb\Model\Movie; - -use Tmdb\Model\AbstractModel; - -class Keyword extends AbstractModel { - - private $id; - private $name; - - public static $_properties = array( - 'id', - 'name', - ); - - /** - * @param mixed $id - * @return $this - */ - public function setId($id) - { - $this->id = (int) $id; - return $this; - } - - /** - * @return integer - */ - public function getId() - { - return $this->id; - } - - /** - * @param mixed $name - * @return $this - */ - public function setName($name) - { - $this->name = $name; - return $this; - } - - /** - * @return mixed - */ - public function getName() - { - return $this->name; - } -} diff --git a/test/Tmdb/Tests/Factory/KeywordFactoryTest.php b/test/Tmdb/Tests/Factory/KeywordFactoryTest.php new file mode 100644 index 00000000..da20092b --- /dev/null +++ b/test/Tmdb/Tests/Factory/KeywordFactoryTest.php @@ -0,0 +1,46 @@ + + * @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'; + } +} \ No newline at end of file diff --git a/test/Tmdb/Tests/Model/Collection/KeywordsTest.php b/test/Tmdb/Tests/Model/Collection/KeywordsTest.php index 72f3f32b..a39b7be5 100644 --- a/test/Tmdb/Tests/Model/Collection/KeywordsTest.php +++ b/test/Tmdb/Tests/Model/Collection/KeywordsTest.php @@ -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 diff --git a/test/Tmdb/Tests/Resources/keywords/get.json b/test/Tmdb/Tests/Resources/keywords/get.json new file mode 100644 index 00000000..5d41cc2b --- /dev/null +++ b/test/Tmdb/Tests/Resources/keywords/get.json @@ -0,0 +1,4 @@ +{ + "id": 1721, + "name": "fight" +} \ No newline at end of file diff --git a/test/Tmdb/Tests/Resources/keywords/movies.json b/test/Tmdb/Tests/Resources/keywords/movies.json new file mode 100644 index 00000000..c493903c --- /dev/null +++ b/test/Tmdb/Tests/Resources/keywords/movies.json @@ -0,0 +1,208 @@ +{ + "id": 1721, + "page": 1, + "results": [ + { + "backdrop_path": "/6xKCYgH16UuwEGAyroLU6p8HLIn.jpg", + "id": 238, + "original_title": "The Godfather", + "release_date": "1972-03-24", + "poster_path": "/d4KNaTrltq6bpkFS01pYtyXa09m.jpg", + "title": "The Godfather", + "vote_average": 9.1999999999999993, + "vote_count": 125 + }, + { + "backdrop_path": "/3R6vDW1yBBzejsma8SzzWuxj2AE.jpg", + "id": 311, + "original_title": "Once Upon a Time in America", + "release_date": "1984-02-17", + "poster_path": "/fqP3Q7DWMFqW7mh11hWXbNwN9rz.jpg", + "title": "Once Upon a Time in America", + "vote_average": 9.0999999999999996, + "vote_count": 34 + }, + { + "backdrop_path": "/jWDegvAE8XO2XDUHP9eQYlepJv1.jpg", + "id": 240, + "original_title": "The Godfather: Part II", + "release_date": "1974-12-20", + "poster_path": "/tHbMIIF51rguMNSastqoQwR0sBs.jpg", + "title": "The Godfather: Part II", + "vote_average": 9.0999999999999996, + "vote_count": 61 + }, + { + "backdrop_path": "/8uO0gUM8aNqYLs1OsTBQiXu0fEv.jpg", + "id": 550, + "original_title": "Fight Club", + "release_date": "1999-10-15", + "poster_path": "/2lECpi35Hnbpa4y46JX0aY3AWTy.jpg", + "title": "Fight Club", + "vote_average": 9.0999999999999996, + "vote_count": 175 + }, + { + "backdrop_path": "/mpYypl40Wg2njmuflqEC3Bs3cFB.jpg", + "id": 19, + "original_title": "Metropolis", + "release_date": "1927-03-13", + "poster_path": "/6oyiv4kiTtroUr42H4kqNwg60rj.jpg", + "title": "Metropolis", + "vote_average": 9.0, + "vote_count": 23 + }, + { + "backdrop_path": "/AplR1QRswlXiM65GoifX8sDadME.jpg", + "id": 213, + "original_title": "North by Northwest", + "release_date": "1959-07-17", + "poster_path": "/rEHP8ylmL3pcsDUEA6Z5qhajYui.jpg", + "title": "North by Northwest", + "vote_average": 9.0, + "vote_count": 28 + }, + { + "backdrop_path": "/qrI7ZgBgBMIsJSbhyezrfP44frb.jpg", + "id": 670, + "original_title": "올드보이", + "release_date": "2003-11-21", + "poster_path": "/jB7ol6ry8dlqMp6kKlKHLfPke4e.jpg", + "title": "Oldboy", + "vote_average": 9.0, + "vote_count": 45 + }, + { + "backdrop_path": "/fRQATr704bMpLc5Skzpj3V9b2iW.jpg", + "id": 197, + "original_title": "Braveheart", + "release_date": "1995-05-24", + "poster_path": "/4T4xQJXSdTNbzUrlT6Eh13kiy5H.jpg", + "title": "Braveheart", + "vote_average": 9.0, + "vote_count": 65 + }, + { + "backdrop_path": "/8BPZO0Bf8TeAy8znF43z8soK3ys.jpg", + "id": 122, + "original_title": "The Lord of the Rings: The Return of the King", + "release_date": "2003-12-17", + "poster_path": "/j6NCjU6Zh7SkfIeN5zDaoTmBn4m.jpg", + "title": "The Lord of the Rings: The Return of the King", + "vote_average": 9.0, + "vote_count": 135 + }, + { + "backdrop_path": "/tv8J6uCTKsTlASa8luJqrFiJlBX.jpg", + "id": 78, + "original_title": "Blade Runner", + "release_date": "1982-06-25", + "poster_path": "/ewq1lwhOT8GqBcQH1w8D1BagwTh.jpg", + "title": "Blade Runner", + "vote_average": 9.0, + "vote_count": 147 + }, + { + "backdrop_path": "/xBKGJQsAIeweesB79KC89FpBrVr.jpg", + "id": 278, + "original_title": "The Shawshank Redemption", + "release_date": "1994-09-14", + "poster_path": "/9O7gLzmreU0nGkIB6K3BsJbzvNv.jpg", + "title": "The Shawshank Redemption", + "vote_average": 9.0, + "vote_count": 173 + }, + { + "backdrop_path": "/8oCkj3t9yvT363svYMssXqGxTRf.jpg", + "id": 824, + "original_title": "Moulin Rouge!", + "release_date": "2001-05-16", + "poster_path": "/vgYM0ZDoeQKZEGxrGAO221J5rIG.jpg", + "title": "Moulin Rouge!", + "vote_average": 8.9000000000000004, + "vote_count": 11 + }, + { + "backdrop_path": "/6yFtd1s69XRTGIOD6yIoZ3EebKx.jpg", + "id": 7549, + "original_title": "Fearless", + "release_date": "2006-01-26", + "poster_path": "/5gqM2IUANPvM5JnB4m5wePhH3Nt.jpg", + "title": "Fearless", + "vote_average": 8.9000000000000004, + "vote_count": 18 + }, + { + "backdrop_path": "/xATZyEpnZ0Z0iO9z5K8RZsraGKI.jpg", + "id": 840, + "original_title": "Close Encounters of the Third Kind", + "release_date": "1977-11-16", + "poster_path": "/mABOVIUl5lB0WF4HG28rfamgxG1.jpg", + "title": "Close Encounters of the Third Kind", + "vote_average": 8.9000000000000004, + "vote_count": 19 + }, + { + "backdrop_path": "/tEm71iwofHgNcqb0Fn1AyH11BNl.jpg", + "id": 11036, + "original_title": "The Notebook", + "release_date": "2004-06-25", + "poster_path": "/gMfstesBXKdsHToAUXVPHujUDfb.jpg", + "title": "The Notebook", + "vote_average": 8.9000000000000004, + "vote_count": 20 + }, + { + "backdrop_path": "/mtJrV7i76PtXJMmWz3tu6dWav6n.jpg", + "id": 510, + "original_title": "One Flew Over the Cuckoo's Nest", + "release_date": "1975-11-19", + "poster_path": "/bYZumDpc1o0adyuAZjXqgkZ182m.jpg", + "title": "One Flew Over the Cuckoo's Nest", + "vote_average": 8.9000000000000004, + "vote_count": 38 + }, + { + "backdrop_path": "/xDEOxA01480uLTWuvQCw61VmDBt.jpg", + "id": 769, + "original_title": "Goodfellas", + "release_date": "1990-09-12", + "poster_path": "/ddMDzejWFbSas5ipUCUCjAlD5dI.jpg", + "title": "Goodfellas", + "vote_average": 8.9000000000000004, + "vote_count": 39 + }, + { + "backdrop_path": "/9yJehIjvR7ULOLxeDJoth4kDDNe.jpg", + "id": 5915, + "original_title": "Into the Wild", + "release_date": "2007-09-21", + "poster_path": "/lHyYgaocXR6KcJLxVmxZDj115hH.jpg", + "title": "Into the Wild", + "vote_average": 8.9000000000000004, + "vote_count": 41 + }, + { + "backdrop_path": "/k4BAPrE5WkNLvpsPsiMfu8W4Zyi.jpg", + "id": 598, + "original_title": "Cidade de Deus", + "release_date": "2002-05-18", + "poster_path": "/gCqnQaq8T4CfioP9uETLx9iMJF4.jpg", + "title": "City of God", + "vote_average": 8.9000000000000004, + "vote_count": 41 + }, + { + "backdrop_path": "/ooqPNPS2WdBH7DgIF4em9e0nEld.jpg", + "id": 857, + "original_title": "Saving Private Ryan", + "release_date": "1998-07-24", + "poster_path": "/35CMz4t7PuUiQqt5h4u5nbrXZlF.jpg", + "title": "Saving Private Ryan", + "vote_average": 8.9000000000000004, + "vote_count": 83 + } + ], + "total_pages": 5, + "total_results": 84 +} \ No newline at end of file