diff --git a/lib/Tmdb/Factory/CreditsFactory.php b/lib/Tmdb/Factory/CreditsFactory.php index 3d7fcc7a..fd096f5c 100644 --- a/lib/Tmdb/Factory/CreditsFactory.php +++ b/lib/Tmdb/Factory/CreditsFactory.php @@ -12,6 +12,7 @@ */ namespace Tmdb\Factory; +use Tmdb\Exception\NotImplementedException; use Tmdb\Model\Collection\Genres; use Tmdb\Model\Genre; use Tmdb\Model\Movie; @@ -77,31 +78,11 @@ public function create(array $data = array()) } /** - * @param array $data - * - * @return Movie - */ - public function createMovie(array $data = array()) - { - return $this->hydrate(new Movie(), $data); - } - - /** - * {@inheritdoc} + * @throws NotImplementedException */ public function createCollection(array $data = array()) { - $collection = new Genres(); - - if (array_key_exists('genres', $data)) { - $data = $data['genres']; - } - - foreach($data as $item) { - $collection->addGenre($this->create($item)); - } - - return $collection; + throw new NotImplementedException('Credits are usually obtained through the PeopleFactory, however we might add a shortcut for that here.'); } /** diff --git a/test/Tmdb/Tests/Factory/CreditsFactoryTest.php b/test/Tmdb/Tests/Factory/CreditsFactoryTest.php new file mode 100644 index 00000000..dc0559f9 --- /dev/null +++ b/test/Tmdb/Tests/Factory/CreditsFactoryTest.php @@ -0,0 +1,116 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Tests\Factory; + +use Tmdb\Factory\CreditsFactory; +use Tmdb\Model\Credits; + +class CreditsFactoryTest extends TestCase +{ + private $data; + + /** + * @var \Tmdb\Model\Credits + */ + private $credits; + + public function setUp() + { + $this->data = $this->loadByFile('credits/get.json'); + + /** + * @var CreditsFactory $factory + */ + $factory = $this->getFactory(); + + /** + * @var Credits $credits + */ + $this->credits = $factory->create($this->data); + } + + /** + * @test + */ + public function shouldBeAbleToSetFactories() + { + /** + * @var CreditsFactory $factory + */ + $factory = $this->getFactory(); + + $class = new \stdClass(); + + $factory->setPeopleFactory($class); + $factory->setTvEpisodeFactory($class); + $factory->setTvSeasonFactory($class); + + $this->assertInstanceOf('stdClass', $factory->getPeopleFactory()); + $this->assertInstanceOf('stdClass', $factory->getTvEpisodeFactory()); + $this->assertInstanceOf('stdClass', $factory->getTvSeasonFactory()); + } + + /** + * @test + * @expectedException Tmdb\Exception\NotImplementedException + */ + public function shouldThrowExceptionForCollection() + { + $factory = $this->getFactory(); + + $factory->createCollection(array()); + } + + /** + * @test + */ + public function shouldBeFunctional() + { + /** + * @var CreditsFactory $factory + */ + $factory = $this->getFactory(); + + $this->assertInstanceOf('Tmdb\Model\Credits', $this->credits); + + $this->assertEquals('cast', $this->credits->getCreditType()); + $this->assertEquals('Actors', $this->credits->getDepartment()); + $this->assertEquals('Actor', $this->credits->getJob()); + + $this->assertInstanceOf('Tmdb\Model\Credits\Media', $this->credits->getMedia()); + $this->assertEquals(5, $this->credits->getMedia()->getId()); + $this->assertEquals('Seinfeld', $this->credits->getMedia()->getName()); + $this->assertEquals('Seinfeld', $this->credits->getMedia()->getOriginalName()); + $this->assertEquals('', $this->credits->getMedia()->getCharacter()); + + $this->assertEquals('tv', $this->credits->getMediaType()); + $this->assertEquals('5240760b5dbf5b0c2c0139db', $this->credits->getId()); + + $this->assertInstanceOf('Tmdb\Model\Person', $this->credits->getPerson()); + $this->assertEquals('Bryan Cranston', $this->credits->getPerson()->getName()); + $this->assertEquals(17419, $this->credits->getPerson()->getId()); + } + + /** + * @test + */ + public function shouldCreateCollection() + { + $this->assertEquals(true, !empty($this->credits)); + } + + protected function getFactoryClass() + { + return 'Tmdb\Factory\CreditsFactory'; + } +} \ No newline at end of file diff --git a/test/Tmdb/Tests/Resources/credits/get.json b/test/Tmdb/Tests/Resources/credits/get.json new file mode 100644 index 00000000..882d1728 --- /dev/null +++ b/test/Tmdb/Tests/Resources/credits/get.json @@ -0,0 +1,60 @@ +{ + "credit_type": "cast", + "department": "Actors", + "job": "Actor", + "media": { + "id": 5, + "name": "Seinfeld", + "original_name": "Seinfeld", + "character": "", + "episodes": [ + { + "air_date": "1994-11-17", + "episode_number": 8, + "name": "The Mom & Pop Store", + "overview": "A salesman convinces George to buy a convertible once owned by \"Jon Voight.\" Kramer tries to save a small shoe-repair business, but his good intentions affect Jerry in a big way. Elaine wins tickets for Mr. Pitt, who's always wanted to participate in the Macy's Thanksgiving Day Parade.", + "season_number": 6, + "still_path": null + }, + { + "air_date": "1995-01-19", + "episode_number": 12, + "name": "The Label Maker", + "overview": "Elaine and Jerry are suspicious of a friend's gift, when a gift Elaine gave him, a label maker, is given to Jerry in return for some Superbowl tickets Jerry has but can't use because \"The Drake\" is getting married on Superbowl Sunday and he is in the wedding party. George convinces his girlfriend to get her male roommate to move out, that he soon regrets. Kramer takes playing a game of Risk against Newman seriously. The Superbowl tickets pass through several hands and Jerry sees the game with his worst nightmare.", + "season_number": 6, + "still_path": null + }, + { + "air_date": "1997-04-24", + "episode_number": 19, + "name": "The Yada Yada", + "overview": "George's girlfriend is big on using the phrase \"yada yada\"; Jerry says at least she is succinct. Jerry's dentist just became Jewish and he is already making jokes that make Jerry uncomfortable. Kramer and Mickey double date but they can't decide which of the women is right for them. Elaine is a character reference for a couple who is trying to adopt; a story she tells during the interview destroys all hope of adoption. George drops by Jerry's dental appointment. Mickey and Kramer continue to fight over who gets Karen or Julie. George determines that his girlfriend might be leaving out some significant details with her overuse of the phrase \"yada yada.\" He gets her to fill in the details and discovers more than he wants to know. Jerry confesses to a priest about what he thinks about Tim's conversion. George drops by Jerry's confession. Kramer decides on the right woman and Mickey also decides to make his a commitment. Tim hears about Jerry's dental joke. After hearing Jerry's complaints about Tim, Kramer accuses Jerry of being an \"anti-dentite.\" Elaine lobbies on behalf of Beth and Arnie and makes a sacrifice to try getting them a child. Meanwhile, Beth comes to Jerry for help when her marriage is falling apart. It does and she accompanies Jerry to Mickey's wedding where she reveals an unknown side of her personality.", + "season_number": 8, + "still_path": null + }, + { + "air_date": "1997-12-18", + "episode_number": 10, + "name": "The Strike", + "overview": "George, Elaine and Jerry attend Tim Whatley's Hanukkah party. Jerry meets an attractive woman with whom he sets up a date. Elaine meets a man in a bad denim vest and gives him her fake number. George is offended by Whatley's gift to him, a donation in his name to a charity. George is also reminded of the Festivus holiday his father created many years ago. Elaine's quest to become a submarine captain and get her free sub sandwich is ruined when she realizes she used her punch card at the party to give her fake number to the denim vested guy. Kramer gets word he can return to his job at the bagel place, it seems he has been on strike for the past 12 years. Elaine goes to the place, an off-track betting parlor, that her fake number reaches. She wanted to give them her real number, so when the denim vest guy calls, she can connect with him. The men at the parlor are interested in connecting with her, so she gives the number for the bagel shop where Kramer is working. Jerry meets his date, Gwen, at a restaurant, but it turns out she is two-faced. Sometimes Gwen looks great, other times she's plain; it all depends on the viewer's angle and the lighting. George decides to use the Whatley approach when giving out Christmas gifts at Krugers; however, he makes up his own charity called the \"Human Fund.\" Kramer is intrigued by the concept of the Festivus holiday and contacts Frank, who becomes excited at the prospect of rekindling \"Festivus for the rest-of-us.\" Kramer asks to get the 23rd of December off, when he can't get it, he resumes the strike; meanwhile Elaine waits at the bagel place for a phone call from the denim vest guy. The look of Jerry's girlfriend keeps changing.\nJerry decides that Gwen looks best in the back booth at Monk's, something she grows to dislike. George passes out his gifts at Krugers and reaps great rewards. Kramer warns Elaine about the sabotage he committed; the bagel place becomes very steamy and makes Elaine look ugly. Kruger gives George a check for donates $20,000 to the \"Human Fund\" and later accounting informs him the charity doesn't exist. Gwen finds out from Kramer that Jerry is seeing another woman, Kramer has seen her and she's not Gwen. Gwen thinks Jerry is two-timing her with an ugly woman. George tries to convince Kruger that he passed out the fake gift cards because he didn't want to be ridiculed for the holiday his family traditionally celebrates, Festivus. To prove it, George brings Kruger to his father's Festivus dinner, where everyone comes together.", + "season_number": 9, + "still_path": null + }, + { + "air_date": "1998-05-14", + "episode_number": 23, + "name": "The Finale, Part 1", + "overview": "Jerry and George discuss the movies and George's desire to get his fifteen minutes of fame. Kramer is off to the beach. Elaine calls a friend, whose father is in the hospital, with her cell phone; Jerry and George tell her that is a social faux pas. Jerry gets a message from NBC that they want to talk about the pilot. So Jerry and George go to meet with the new vice president of programming, who is interested in turning their pilot into a 13 episode series. Jerry and George begin to make plans to move to California. Jerry interrupts Elaine's phone call to her friend to tell her about the NBC deal. When he finds out what she did, he tells her that was an even greater faux pas than the cell phone. Jerry and George's parents are excited by the news about the NBC deal. NBC offers Jerry George a perk, free use of one of their private jets to anywhere they want. Kramer returns from the beach, but has a little bit of water trapped in his ear. Kramer warns they'll never come back from LA, \"she's a seductress.\" Hey! He did. The foursome decides where they want to take the private jet. They finally decide on Paris. As they are ready to leave, Elaine plans to call her friend again; Jerry tells her it is not right to rush that kind of phone call. Elaine avoids a faux pas. Newman begs to be brought along, when Jerry denies him, he vows to be there at Jerry's day of reckoning. The private jet, except for George who wanted the one Ted Danson would have gotten impresses everyone. With water still in his ear, Kramer tries to get it out mid-flight. He stumbles into the cockpit and the plane starts going into a crash dive. During the descent, George confesses he cheated during \"the contest\" and Elaine and Jerry are about to tell each other something important, when the plane corrects itself. The plane puts down in the small town of Latham, Massachusetts for a checkup. The foursome goes into town and debates about if they are going to get back on the plane. They witness the robbery of a fat guy, which they all mock and Kramer videotapes. They are arrested under the Good Samaritan law established by the town. They are looking at a fine of a maximum of $85,000 and up to five years in prison. The guard assumes they are going to be prosecuted since this is the first offense of this kind in the country. Jackie Chiles is called in for their defense. The prosecution decides to look into the past of these four and build a case that will destroy their characters. Rivera Live covers the trial. Jerry and George's parents prepare to go to Latham for the trial. Newman (who's absolutely delighted), Uncle Leo, Peterman, Puddy, Mickey, Bania, Mr. Mrs. Ross, Rabbi Glickman, Keith Hernandez and George Steinbrenner also make their way to Latham. Jackie tries to give George a moral compass. The judge, Arthur Vandelay, begins the trial. George thinks the name might be a good sign. The trial begins with opening arguments.", + "season_number": 9, + "still_path": null + } + ], + "seasons": [] + }, + "media_type": "tv", + "id": "5240760b5dbf5b0c2c0139db", + "person": { + "name": "Bryan Cranston", + "id": 17419 + } +} \ No newline at end of file