Skip to content

Commit

Permalink
Unit tests for Review also adjusted the MovieFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfzdotnet committed Feb 22, 2014
1 parent 849d9e5 commit dc4000f
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/Tmdb/Factory/AbstractFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected function createGenericCollection(array $data = array(), $class)
*
* @param array $data
* @param string $method
* @return GenericCollection
* @return ResultCollection
*/
public function createResultCollection(array $data = array(), $method = 'create')
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Tmdb/Factory/MovieFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public function create(array $data = array())
}

if (array_key_exists('reviews', $data)) {
$movie->setReviews($this->getReviewFactory()->createCollection($data['reviews']));
$movie->setReviews($this->getReviewFactory()->createResultCollection($data['reviews']));
}

if (array_key_exists('lists', $data)) {
Expand Down
80 changes: 80 additions & 0 deletions lib/Tmdb/Model/Review.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,20 @@ class Review extends AbstractModel {
private $id;
private $author;
private $content;
private $iso6391;
private $mediaId;
private $mediaTitle;
private $mediaType;
private $url;

public static $_properties = array(
'id',
'author',
'content',
'iso_639_1',
'media_id',
'media_title',
'media_type',
'url'
);

Expand Down Expand Up @@ -80,6 +88,78 @@ public function getId()
return $this->id;
}

/**
* @param mixed $iso6391
* @return $this
*/
public function setIso6391($iso6391)
{
$this->iso6391 = $iso6391;
return $this;
}

/**
* @return mixed
*/
public function getIso6391()
{
return $this->iso6391;
}

/**
* @param mixed $mediaId
* @return $this
*/
public function setMediaId($mediaId)
{
$this->mediaId = $mediaId;
return $this;
}

/**
* @return mixed
*/
public function getMediaId()
{
return $this->mediaId;
}

/**
* @param mixed $mediaTitle
* @return $this
*/
public function setMediaTitle($mediaTitle)
{
$this->mediaTitle = $mediaTitle;
return $this;
}

/**
* @return mixed
*/
public function getMediaTitle()
{
return $this->mediaTitle;
}

/**
* @param mixed $mediaType
* @return $this
*/
public function setMediaType($mediaType)
{
$this->mediaType = $mediaType;
return $this;
}

/**
* @return mixed
*/
public function getMediaType()
{
return $this->mediaType;
}

/**
* @param mixed $url
* @return $this
Expand Down
59 changes: 59 additions & 0 deletions test/Tmdb/Tests/Factory/ReviewFactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?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\ReviewFactory;
use Tmdb\Model\Review;

class ReviewFactoryTest extends TestCase
{
private $data;

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

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

/**
* @var Review $review
*/
$review = $factory->create($this->data);

$review->setContent('content-test');

$this->assertInstanceOf('Tmdb\Model\Review', $review);
$this->assertEquals('5013bc76760ee372cb00253e', $review->getId());
$this->assertEquals('Chris', $review->getAuthor());
$this->assertEquals('content-test', $review->getContent());
$this->assertEquals('en', $review->getIso6391());
$this->assertEquals(49026, $review->getMediaId());
$this->assertEquals('The Dark Knight Rises', $review->getMediaTitle());
$this->assertEquals('Movie', $review->getMediaType());
$this->assertEquals('http://j.mp/P18dg1', $review->getUrl());
}

protected function getFactoryClass()
{
return 'Tmdb\Factory\ReviewFactory';
}
}
10 changes: 10 additions & 0 deletions test/Tmdb/Tests/Resources/reviews/get.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"id": "5013bc76760ee372cb00253e",
"author": "Chris",
"content": "I personally thought this film is on par if not better than the Dark Knight.\r\n\r\nWhilst some think the film is too long for the story I didn't find this. The length of the film is longer than some (but doesn't feel it), I liked that the film took it's time rather than shoving more elements in it - I think this contributed to the dramatic ending (much like a classical piece of music will be relaxed and calm before the final crescendo).\r\n\r\nAt the end of the day whether you like this film will boil down to if you like films Christopher Nolan has directed and/or you like the Christopher Nolan Batman series so far.\r\n\r\nStupendously good film in my opinion.",
"iso_639_1": "en",
"media_id": 49026,
"media_title": "The Dark Knight Rises",
"media_type": "Movie",
"url": "http://j.mp/P18dg1"
}

0 comments on commit dc4000f

Please sign in to comment.