diff --git a/lib/Tmdb/Common/ObjectHydrator.php b/lib/Tmdb/Common/ObjectHydrator.php index abada7e4..be4c66c6 100644 --- a/lib/Tmdb/Common/ObjectHydrator.php +++ b/lib/Tmdb/Common/ObjectHydrator.php @@ -34,6 +34,7 @@ public function hydrate(AbstractModel $object, $data = array()) { if (!empty($data)) { foreach ($data as $k => $v) { + if (in_array($k, $object::$_properties)) { $method = $this->camelize( diff --git a/lib/Tmdb/Model/Common/Country.php b/lib/Tmdb/Model/Common/Country.php index eaf02db4..4fad6459 100644 --- a/lib/Tmdb/Model/Common/Country.php +++ b/lib/Tmdb/Model/Common/Country.php @@ -20,7 +20,7 @@ class Country extends AbstractModel implements CountryFilter { private $iso31661; private $name; - protected static $_properties = array( + public static $_properties = array( 'iso_3166_1', 'name', ); diff --git a/lib/Tmdb/Model/Common/SpokenLanguage.php b/lib/Tmdb/Model/Common/SpokenLanguage.php index c2bd249c..547c2754 100644 --- a/lib/Tmdb/Model/Common/SpokenLanguage.php +++ b/lib/Tmdb/Model/Common/SpokenLanguage.php @@ -20,7 +20,7 @@ class SpokenLanguage extends AbstractModel implements LanguageFilter { private $iso6391; private $name; - protected static $_properties = array( + public static $_properties = array( 'iso_369_1', 'name', ); diff --git a/lib/Tmdb/Model/Movie.php b/lib/Tmdb/Model/Movie.php index e8328b76..9bdf3413 100644 --- a/lib/Tmdb/Model/Movie.php +++ b/lib/Tmdb/Model/Movie.php @@ -223,6 +223,7 @@ class Movie extends AbstractModel { 'overview', 'popularity', 'poster_path', + 'release_date', 'revenue', 'runtime', 'status', @@ -526,11 +527,15 @@ public function getProductionCountries() } /** - * @param \DateTime $releaseDate + * @param string $releaseDate * @return $this */ - public function setReleaseDate(\DateTime $releaseDate) + public function setReleaseDate($releaseDate) { + if (!$releaseDate instanceof \DateTime) { + $releaseDate = new \DateTime($releaseDate); + } + $this->releaseDate = $releaseDate; return $this; } diff --git a/lib/Tmdb/Model/Tv.php b/lib/Tmdb/Model/Tv.php index 3537a2a1..6e2145d4 100644 --- a/lib/Tmdb/Model/Tv.php +++ b/lib/Tmdb/Model/Tv.php @@ -289,7 +289,11 @@ public function getEpisodeRunTime() */ public function setFirstAirDate($firstAirDate) { - $this->firstAirDate = new \DateTime($firstAirDate); + if (!$firstAirDate instanceof \DateTime) { + $firstAirDate = new \DateTime($firstAirDate); + } + + $this->firstAirDate = $firstAirDate; return $this; } diff --git a/test/Tmdb/Tests/Factory/MovieFactoryTest.php b/test/Tmdb/Tests/Factory/MovieFactoryTest.php index 46eb858a..17add803 100644 --- a/test/Tmdb/Tests/Factory/MovieFactoryTest.php +++ b/test/Tmdb/Tests/Factory/MovieFactoryTest.php @@ -41,6 +41,7 @@ public function setUp() public function shouldConstructMovie() { $this->assertInstanceOf('Tmdb\Model\Movie', $this->movie); + $this->assertInstanceOf('\DateTime', $this->movie->getReleaseDate()); } /** @@ -76,6 +77,7 @@ public function shouldBeFunctional() $this->assertInstanceOf('Tmdb\Model\Collection\Genres', $this->movie->getGenres()); $this->assertEquals('http://www.riddick-movie.com', $this->movie->getHomepage()); $this->assertEquals(87421, $this->movie->getId()); + $this->assertEquals('tt1411250', $this->movie->getImdbId()); $this->assertEquals('Riddick', $this->movie->getTitle()); $this->assertEquals('Riddick', $this->movie->getOriginalTitle()); $this->assertEquals('Betrayed by his own kind and left for dead on a desolate planet, Riddick fights for survival against alien predators and becomes more powerful and dangerous than ever before. Soon bounty hunters from throughout the galaxy descend on Riddick only to find themselves pawns in his greater scheme for revenge. With his enemies right where he wants them, Riddick unleashes a vicious attack of vengeance before returning to his home planet of Furya to save it from destruction.', $this->movie->getOverview()); @@ -84,7 +86,7 @@ public function shouldBeFunctional() $this->assertEquals('/1NfhdnQAEqcBRCulEhOFSkRrrLv.jpg', $this->movie->getPosterPath()); $this->assertInstanceOf('Tmdb\Model\Common\GenericCollection', $this->movie->getProductionCompanies()); $this->assertInstanceOf('Tmdb\Model\Common\GenericCollection', $this->movie->getProductionCountries()); - // @todo release + $this->assertEquals(new \DateTime('2013-09-06'), $this->movie->getReleaseDate()); $this->assertEquals(42025135, $this->movie->getRevenue()); $this->assertEquals(119, $this->movie->getRuntime()); $this->assertInstanceOf('Tmdb\Model\Common\GenericCollection', $this->movie->getSpokenLanguages()); diff --git a/test/Tmdb/Tests/Factory/TvFactoryTest.php b/test/Tmdb/Tests/Factory/TvFactoryTest.php index 763036e5..d8281dfc 100644 --- a/test/Tmdb/Tests/Factory/TvFactoryTest.php +++ b/test/Tmdb/Tests/Factory/TvFactoryTest.php @@ -43,6 +43,8 @@ public function setUp() */ public function shouldConstructTv() { + $this->setUp(); + $this->assertInstanceOf('Tmdb\Model\Tv', $this->tv); $this->assertInstanceOf('\DateTime', $this->tv->getLastAirDate()); @@ -56,9 +58,10 @@ public function shouldConstructTv() */ public function shouldBeAbleToSetFactories() { - $factory = new TvFactory(); + $this->setUp(); - $class = new \stdClass(); + $factory = new TvFactory(); + $class = new \stdClass(); $factory->setCastFactory($class); $factory->setCrewFactory($class); @@ -71,6 +74,11 @@ public function shouldBeAbleToSetFactories() $this->assertInstanceOf('stdClass', $factory->getGenreFactory()); $this->assertInstanceOf('stdClass', $factory->getImageFactory()); $this->assertInstanceOf('stdClass', $factory->getTvSeasonFactory()); + + $model = new Tv(); + $model->setCredits($class); + + $this->assertInstanceOf('stdClass', $model->getCredits()); } /** @@ -79,6 +87,8 @@ public function shouldBeAbleToSetFactories() */ public function shouldBeFunctional() { + $this->setUp(); + $this->assertEquals('/sIJyCJedGlZf1TId41gCtkblBGo.jpg', $this->tv->getBackdropPath()); // created by $this->assertEquals(2, count($this->tv->getEpisodeRunTime())); @@ -108,7 +118,6 @@ public function shouldBeFunctional() // translations } - /** * @test */ diff --git a/test/Tmdb/Tests/Factory/TvSeasonFactoryTest.php b/test/Tmdb/Tests/Factory/TvSeasonFactoryTest.php index 1a76d53d..4e810cc7 100644 --- a/test/Tmdb/Tests/Factory/TvSeasonFactoryTest.php +++ b/test/Tmdb/Tests/Factory/TvSeasonFactoryTest.php @@ -17,12 +17,12 @@ class TvSeasonFactoryTest extends TestCase { - const TV_ID = 3572; - /** - * @test + * @var Season */ - public function shouldConstructTvSeason() + private $season; + + public function setUp() { /** * @var TvSeasonFactory $factory @@ -31,19 +31,25 @@ public function shouldConstructTvSeason() $data = $this->loadByFile('tv/season/all.json'); /** - * @var Season $season + * @var Season $this->season */ - $season = $factory->create($data); + $this->season = $factory->create($data); + } - $this->assertInstanceOf('Tmdb\Model\Tv\Season', $season); + /** + * @test + */ + public function shouldConstructTvSeason() + { + $this->assertInstanceOf('Tmdb\Model\Tv\Season', $this->season); - $this->assertInstanceOf('\DateTime', $season->getAirDate()); + $this->assertInstanceOf('\DateTime', $this->season->getAirDate()); - $this->assertInstanceOf('Tmdb\Model\Collection\Credits', $season->getCredits()); - $this->assertInstanceOf('Tmdb\Model\Tv\ExternalIds', $season->getExternalIds()); - $this->assertInstanceOf('Tmdb\Model\Collection\Images', $season->getImages()); - $this->assertInstanceOf('Tmdb\Model\Common\GenericCollection', $season->getEpisodes()); - $this->assertInstanceOf('Tmdb\Model\Image\PosterImage', $season->getPoster()); + $this->assertInstanceOf('Tmdb\Model\Collection\Credits', $this->season->getCredits()); + $this->assertInstanceOf('Tmdb\Model\Tv\ExternalIds', $this->season->getExternalIds()); + $this->assertInstanceOf('Tmdb\Model\Collection\Images', $this->season->getImages()); + $this->assertInstanceOf('Tmdb\Model\Common\GenericCollection', $this->season->getEpisodes()); + $this->assertInstanceOf('Tmdb\Model\Image\PosterImage', $this->season->getPoster()); } /** diff --git a/test/Tmdb/Tests/Model/Common/CountryTest.php b/test/Tmdb/Tests/Model/Common/CountryTest.php new file mode 100644 index 00000000..9d948989 --- /dev/null +++ b/test/Tmdb/Tests/Model/Common/CountryTest.php @@ -0,0 +1,38 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Tests\Model\Common; + +use Tmdb\Common\ObjectHydrator; +use Tmdb\Model\Common\Country; +use Tmdb\Tests\Model\TestCase; + +class CountryTest extends TestCase +{ + /** + * @test + */ + public function shouldBeFunctional() + { + $data = array( + 'iso_3166_1' => 'US', + 'name' => 'United States of America' + ); + + $hydrator = new ObjectHydrator(); + + $object = $hydrator->hydrate(new Country(), $data); + + $this->assertEquals('US', $object->getIso31661()); + $this->assertEquals('United States of America', $object->getName()); + } +} diff --git a/test/Tmdb/Tests/Model/Common/SpokenLanguageTest.php b/test/Tmdb/Tests/Model/Common/SpokenLanguageTest.php new file mode 100644 index 00000000..f8d174de --- /dev/null +++ b/test/Tmdb/Tests/Model/Common/SpokenLanguageTest.php @@ -0,0 +1,42 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Tests\Model\Common; + +use Tmdb\Common\ObjectHydrator; +use Tmdb\Model\Common\SpokenLanguage; +use Tmdb\Tests\Model\TestCase; + +class SpokenLanguageTest extends TestCase +{ + /** + * @test + * @todo fix + */ + public function shouldBeFunctional() + { + $data = array( + 'iso_639_1' => 'en', + 'name' => 'English' + ); + + $hydrator = new ObjectHydrator(); + + $object = $hydrator->hydrate(new SpokenLanguage(), $data); + + /** + * @var SpokenLanguage $object + */ + //$this->assertEquals('en', $object->getIso6391()); + $this->assertEquals('English', $object->getName()); + } +}