Skip to content

Commit

Permalink
Adding unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfzdotnet committed Jan 29, 2014
1 parent 04dc350 commit ad9408b
Show file tree
Hide file tree
Showing 26 changed files with 586 additions and 43 deletions.
21 changes: 0 additions & 21 deletions examples/people/model/get.php

This file was deleted.

9 changes: 1 addition & 8 deletions lib/Tmdb/Factory/CompanyFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
*/
namespace Tmdb\Factory;

use Tmdb\Model\Common\GenericCollection;
use Tmdb\Model\Company;

class CompanyFactory extends AbstractFactory
Expand All @@ -30,12 +29,6 @@ public function create(array $data = array())
*/
public function createCollection(array $data = array())
{
$collection = new GenericCollection();

foreach($data as $item) {
$collection->add(null, $this->create($item));
}

return $collection;
return array();
}
}
2 changes: 1 addition & 1 deletion lib/Tmdb/Factory/ConfigurationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ public function create(array $data = array())
*/
public function createCollection(array $data = array())
{
return null;
return array();
}
}
2 changes: 2 additions & 0 deletions lib/Tmdb/Factory/People/CastFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
*/
namespace Tmdb\Factory\People;

use Tmdb\Factory\PeopleFactory;

use Tmdb\Model\Collection\People\Cast;

class CastFactory extends PeopleFactory
Expand Down
2 changes: 2 additions & 0 deletions lib/Tmdb/Factory/People/CrewFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
*/
namespace Tmdb\Factory\People;

use Tmdb\Factory\PeopleFactory;

use Tmdb\Model\Collection\People\Crew;

class CrewFactory extends PeopleFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@
* @copyright (c) 2013, Michael Roterman
* @version 0.0.1
*/
namespace Tmdb\Factory\People;
namespace Tmdb\Factory;

use Tmdb\Factory\AbstractFactory;
use Tmdb\Factory\ImageFactory;
use Tmdb\Model\Common\GenericCollection;
use Tmdb\Model\Person\CastMember;
use Tmdb\Model\Person\CrewMember;
Expand Down
2 changes: 1 addition & 1 deletion lib/Tmdb/Factory/TvEpisodeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function create(array $data = array())

/** Images */
if (array_key_exists('images', $data)) {
$tvEpisode->setImages($this->getImageFactory()->createCollectionFromTv($data['images']));
$tvEpisode->setImages($this->getImageFactory()->createCollectionFromTvEpisode($data['images']));
}

return $this->hydrate($tvEpisode, $data);
Expand Down
2 changes: 1 addition & 1 deletion lib/Tmdb/Factory/TvSeasonFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function create(array $data = array())

/** Images */
if (array_key_exists('images', $data)) {
$tvSeason->setImages($this->getImageFactory()->createCollectionFromTv($data['images']));
$tvSeason->setImages($this->getImageFactory()->createCollectionFromTvSeason($data['images']));
}

/** Episodes */
Expand Down
1 change: 1 addition & 0 deletions lib/Tmdb/Helper/ImageHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public function getHtml(Image $image, $size = 'original', $width = null, $height
}

$aspectRatio = $image->getAspectRatio();

if (null !== $width && null == $height && $aspectRatio !== null) {
$height = round($width / $aspectRatio);
}
Expand Down
6 changes: 2 additions & 4 deletions lib/Tmdb/Model/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,15 @@
*/
namespace Tmdb\Model;

use Tmdb\Model\Common\GenericCollection;

class Configuration extends AbstractModel {

/**
* @var Collection
* @var array
*/
private $images;

/**
* @var Collection
* @var array
*/
private $change_keys;

Expand Down
2 changes: 1 addition & 1 deletion lib/Tmdb/Repository/ChangesRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use Tmdb\Exception\NotImplementedException;
use Tmdb\Factory\MovieFactory;
use Tmdb\Factory\People\PeopleFactory;
use Tmdb\Factory\PeopleFactory;
use Tmdb\Model\Collection\People;
use Tmdb\Model\Query\ChangesQuery;

Expand Down
2 changes: 1 addition & 1 deletion lib/Tmdb/Repository/PeopleRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
namespace Tmdb\Repository;

use Tmdb\Api\People;
use Tmdb\Factory\People\PeopleFactory;
use Tmdb\Factory\PeopleFactory;
use Tmdb\Model\Person;
use Tmdb\Model\Person\QueryParameter\AppendToResponse;

Expand Down
62 changes: 62 additions & 0 deletions test/Tmdb/Tests/Factory/CollectionFactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?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\CollectionFactory;
use Tmdb\Model\Collection;

class CollectionFactoryTest extends TestCase
{
/**
* @test
*/
public function shouldConstructCollection()
{
/**
* @var CollectionFactory $factory
*/
$factory = $this->getFactory();
$data = $this->loadByFile('collection/get.json');

/**
* @var Collection $collection
*/
$collection = $factory->create($data);

$this->assertInstanceOf('Tmdb\Model\Collection', $collection);
}

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

$class = new \stdClass();

$factory->setMovieFactory($class);
$factory->setImageFactory($class);

$this->assertInstanceOf('stdClass', $factory->getMovieFactory());
$this->assertInstanceOf('stdClass', $factory->getImageFactory());
}

protected function getFactoryClass()
{
return 'Tmdb\Factory\CollectionFactory';
}
}
54 changes: 52 additions & 2 deletions test/Tmdb/Tests/Factory/CompanyFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,34 @@
*/
namespace Tmdb\Tests\Factory;

use Tmdb\Factory\CompanyFactory;
use Tmdb\Model\Company;

class CompanyFactoryTest extends TestCase
{
const COMPANY_ID = 1;

private $data;

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

/**
* @test
*/
public function shouldConstructCompany()
{
/**
* @var CompanyFactory $factory
*/
$factory = $this->getFactory();
$data = $this->loadByFile('company/get.json');

$company = $factory->create($data);
/**
* @var Company $company
*/
$company = $factory->create($this->data);

$this->assertInstanceOf('Tmdb\Model\Company', $company);
$this->assertInstanceOf('Tmdb\Model\Image\LogoImage', $company->getLogo());
Expand All @@ -38,6 +53,41 @@ public function shouldConstructCompany()
$this->assertEquals(null, $company->getParentCompany());
}

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

/**
* @var Company $company
*/
$company = $factory->create($this->data);

$this->assertEquals(null, $company->getDescription());
$this->assertEquals('San Francisco, California', $company->getHeadquarters());
$this->assertEquals('http://www.lucasfilm.com', $company->getHomepage());
$this->assertEquals(1, $company->getId());
$this->assertEquals('/8rUnVMVZjlmQsJ45UGotD0Uznxj.png', $company->getLogoPath());
$this->assertEquals('Lucasfilm', $company->getName());
$this->assertEquals(null, $company->getParentCompany());
}

/**
* @test
*/
public function callingCollectionReturnsEmptyArray()
{
$factory = $this->getFactory();
$collection = $factory->createCollection(array());

$this->assertEquals(array(), $collection);
}

protected function getFactoryClass()
{
return 'Tmdb\Factory\CompanyFactory';
Expand Down
62 changes: 62 additions & 0 deletions test/Tmdb/Tests/Factory/ConfigurationFactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?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\ConfigurationFactory;
use Tmdb\Model\Configuration;

class ConfigurationFactoryTest extends TestCase
{
/**
* @test
*/
public function shouldConstructConfiguration()
{
/**
* @var ConfigurationFactory $factory
*/
$factory = $this->getFactory();
$data = $this->loadByFile('configuration/get.json');

/**
* @var Configuration $configuration
*/
$configuration = $factory->create($data);

$this->assertInstanceOf('Tmdb\Model\Configuration', $configuration);

$images = $configuration->getImages();
$changeKeys = $configuration->getChangeKeys();

$this->assertEquals(true, !empty($images));
$this->assertEquals(true, !empty($changeKeys));
}

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

$this->assertEquals(array(), $factory->createCollection(array()));
}

protected function getFactoryClass()
{
return 'Tmdb\Factory\ConfigurationFactory';
}
}
Loading

0 comments on commit ad9408b

Please sign in to comment.