Skip to content

Commit

Permalink
Updating unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfzdotnet committed Feb 26, 2014
1 parent e62f084 commit ddc0af3
Show file tree
Hide file tree
Showing 16 changed files with 1,157 additions and 6 deletions.
32 changes: 31 additions & 1 deletion lib/Tmdb/Factory/AccountFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,15 @@ class AccountFactory extends AbstractFactory
*/
private $movieFactory;

/**
* @var ImageFactory
*/
private $imageFactory;

public function __construct()
{
$this->movieFactory = new MovieFactory();
$this->imageFactory = new ImageFactory();
}

/**
Expand Down Expand Up @@ -66,7 +72,13 @@ public function createMovie(array $data = array()) {
*/
public function createListItem(array $data = array())
{
return $this->hydrate(new Account\ListItem(), $data);
$listItem = new Account\ListItem();

if (array_key_exists('poster_path', $data)) {
$listItem->setPosterImage($this->getImageFactory()->createFromPath($data['poster_path'], 'poster_path'));
}

return $this->hydrate($listItem, $data);
}

/**
Expand Down Expand Up @@ -94,4 +106,22 @@ public function getMovieFactory()
{
return $this->movieFactory;
}

/**
* @param \Tmdb\Factory\ImageFactory $imageFactory
* @return $this
*/
public function setImageFactory($imageFactory)
{
$this->imageFactory = $imageFactory;
return $this;
}

/**
* @return \Tmdb\Factory\ImageFactory
*/
public function getImageFactory()
{
return $this->imageFactory;
}
}
164 changes: 164 additions & 0 deletions test/Tmdb/Tests/Factory/AccountFactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
<?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\AccountFactory;
use Tmdb\Model\Account;
use Tmdb\Model\Collection\ResultCollection;

class AccountFactoryTest extends TestCase
{
/**
* @test
*/
public function shouldGetAccount()
{
/**
* @var AccountFactory $factory
*/
$factory = $this->getFactory();

/**
* @var Account $account
*/
$account = $factory->create($this->loadByFile('account/get.json'));

$this->assertEquals(36, $account->getId());
$this->assertEquals(false, $account->getIncludeAdult());
$this->assertEquals('US', $account->getIso31661());
$this->assertEquals('en', $account->getIso6391());
$this->assertEquals('John Doe', $account->getName());
$this->assertEquals('johndoe', $account->getUsername());
}

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

/**
* @var ResultCollection $collection
*/
$collection = $factory->createResultCollection($this->loadByFile('account/lists.json'), 'createListItem');

$this->assertInstanceOf('Tmdb\Model\Collection\ResultCollection', $collection);
$this->assertEquals(1, $collection->getPage());
$this->assertEquals(1, $collection->getTotalPages());
$this->assertEquals(15, $collection->getTotalResults());
}

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

/**
* @var ResultCollection $collection
*/
$collection = $factory->createResultCollection($this->loadByFile('account/favorite_movies.json'), 'createMovie');

$this->assertInstanceOf('Tmdb\Model\Collection\ResultCollection', $collection);
$this->assertEquals(1, $collection->getPage());
$this->assertEquals(2, $collection->getTotalPages());
$this->assertEquals(34, $collection->getTotalResults());
}

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

$status = $factory->createStatusResult($this->loadByFile('account/favorite.json'));

$this->assertEquals(12, $status->getStatusCode());
$this->assertEquals('The item/record was updated successfully', $status->getStatusMessage());
}

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

/**
* @var ResultCollection $collection
*/
$collection = $factory->createResultCollection($this->loadByFile('account/rated_movies.json'), 'createMovie');

$this->assertInstanceOf('Tmdb\Model\Collection\ResultCollection', $collection);
$this->assertEquals(1, $collection->getPage());
$this->assertEquals(12, $collection->getTotalPages());
$this->assertEquals(239, $collection->getTotalResults());
}

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

/**
* @var ResultCollection $collection
*/
$collection = $factory->createResultCollection($this->loadByFile('account/movie_watchlist.json'), 'createMovie');

$this->assertInstanceOf('Tmdb\Model\Collection\ResultCollection', $collection);
$this->assertEquals(1, $collection->getPage());
$this->assertEquals(4, $collection->getTotalPages());
$this->assertEquals(67, $collection->getTotalResults());
}

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

$status = $factory->createStatusResult($this->loadByFile('account/watchlist.json'));

$this->assertEquals(1, $status->getStatusCode());
$this->assertEquals('Success', $status->getStatusMessage());
}

protected function getFactoryClass()
{
return 'Tmdb\Factory\AccountFactory';
}
}
101 changes: 101 additions & 0 deletions test/Tmdb/Tests/Factory/AuthenticationFactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?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\AuthenticationFactory;

class AuthenticationFactoryTest extends TestCase
{
/**
* @test
*/
public function shouldCreateRequestToken()
{
/**
* @var AuthenticationFactory $factory
*/
$factory = $this->getFactory();

$token = $factory->createRequestToken($this->loadByFile('authentication/request_token.json'));

$this->assertEquals('09-02-2012', $token->getExpiresAt()->format('d-m-Y'));
$this->assertEquals('641bf16c663db167c6cffcdff41126039d4445bf', $token->getToken());
$this->assertEquals(true, $token->getSuccess());
}

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

$token = $factory->createSessionToken($this->loadByFile('authentication/session_token.json'));

$this->assertEquals('80b2bf99520cd795ff54e31af97917bc9e3a7c8c', $token->getToken());
$this->assertEquals(true, $token->getSuccess());
}

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

$token = $factory->createGuestSessionToken($this->loadByFile('authentication/guest_session_token.json'));

$this->assertEquals('04-12-2012', $token->getExpiresAt()->format('d-m-Y'));
$this->assertEquals('0c550fd5da2fc3f321ab3bs9b60ca108', $token->getToken());
$this->assertEquals(true, $token->getSuccess());
}

/**
* @test
* @expectedException \Tmdb\Exception\NotImplementedException
*/
public function shouldThrowExceptionForCreate()
{
/**
* @var AuthenticationFactory $factory
*/
$factory = $this->getFactory();

$factory->create(array());
}

/**
* @test
* @expectedException \Tmdb\Exception\NotImplementedException
*/
public function shouldThrowExceptionForCreateCollection()
{
/**
* @var AuthenticationFactory $factory
*/
$factory = $this->getFactory();

$factory->createCollection(array());
}

protected function getFactoryClass()
{
return 'Tmdb\Factory\AuthenticationFactory';
}
}
5 changes: 1 addition & 4 deletions test/Tmdb/Tests/Factory/ChangesFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,9 @@

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

class ChangesFactoryTest extends TestCase
{
const COMPANY_ID = 1;

private $data;

/**
Expand All @@ -37,7 +34,7 @@ public function setUp()
$factory = $this->getFactory();

/**
* @var Company $company
* @var Changes $changes
*/
$this->changes = $factory->createCollection($this->data);
}
Expand Down
13 changes: 12 additions & 1 deletion test/Tmdb/Tests/Repository/AuthenticationRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Tmdb\Model\Movie;
use Tmdb\Repository\AuthenticationRepository;
use Tmdb\RequestToken;
use Tmdb\SessionToken;

class AuthenticationRepositoryTest extends TestCase
{
Expand All @@ -42,6 +41,18 @@ public function shouldGetSessionToken()
$repository->getSessionToken($token);
}

/**
* @test
*/
public function shouldAuthenticateRequestToken()
{
$repository = $this->getRepositoryWithMockedHttpClient();

$token = new RequestToken('test');

$repository->getSessionToken($token);
}

/**
* @test
*/
Expand Down
20 changes: 20 additions & 0 deletions test/Tmdb/Tests/Repository/MovieRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,26 @@ public function shouldGetTopRated()
$repository->getTopRated();
}

/**
* @test
*/
public function shouldGetAccountStates()
{
$repository = $this->getRepositoryWithMockedHttpClient();

$repository->getAccountStates('id');
}

/**
* @test
*/
public function shouldRate()
{
$repository = $this->getRepositoryWithMockedHttpClient();

$repository->rate('id', 5.2);
}

/**
* @test
*/
Expand Down
Loading

0 comments on commit ddc0af3

Please sign in to comment.