Skip to content

Commit

Permalink
Expanding test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfzdotnet committed Feb 5, 2014
1 parent bf0a0f8 commit f6d18bc
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 22 deletions.
1 change: 1 addition & 0 deletions lib/Tmdb/Common/ObjectHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion lib/Tmdb/Model/Common/Country.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
);
Expand Down
2 changes: 1 addition & 1 deletion lib/Tmdb/Model/Common/SpokenLanguage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
);
Expand Down
9 changes: 7 additions & 2 deletions lib/Tmdb/Model/Movie.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ class Movie extends AbstractModel {
'overview',
'popularity',
'poster_path',
'release_date',
'revenue',
'runtime',
'status',
Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 5 additions & 1 deletion lib/Tmdb/Model/Tv.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 3 additions & 1 deletion test/Tmdb/Tests/Factory/MovieFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function setUp()
public function shouldConstructMovie()
{
$this->assertInstanceOf('Tmdb\Model\Movie', $this->movie);
$this->assertInstanceOf('\DateTime', $this->movie->getReleaseDate());
}

/**
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand Down
15 changes: 12 additions & 3 deletions test/Tmdb/Tests/Factory/TvFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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);
Expand All @@ -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());
}

/**
Expand All @@ -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()));
Expand Down Expand Up @@ -108,7 +118,6 @@ public function shouldBeFunctional()
// translations
}


/**
* @test
*/
Expand Down
32 changes: 19 additions & 13 deletions test/Tmdb/Tests/Factory/TvSeasonFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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());
}

/**
Expand Down
38 changes: 38 additions & 0 deletions test/Tmdb/Tests/Model/Common/CountryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?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\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());
}
}
42 changes: 42 additions & 0 deletions test/Tmdb/Tests/Model/Common/SpokenLanguageTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?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\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());
}
}

0 comments on commit f6d18bc

Please sign in to comment.