Skip to content

Commit

Permalink
Adding basic tests for movies
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfzdotnet committed Jan 23, 2014
1 parent f0fc9d1 commit 38450c0
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 20 deletions.
18 changes: 18 additions & 0 deletions lib/Tmdb/HttpClient/HttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,22 @@ public function request(RequestInterface $request)

return $response;
}

/**
* @param \Guzzle\Http\ClientInterface $client
* @return $this
*/
public function setClient($client)
{
$this->client = $client;
return $this;
}

/**
* @return \Guzzle\Http\ClientInterface
*/
public function getClient()
{
return $this->client;
}
}
6 changes: 3 additions & 3 deletions lib/Tmdb/Repository/AbstractRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

abstract class AbstractRepository {

private static $client = null;
protected $client = null;

protected $api = null;

Expand All @@ -32,7 +32,7 @@ abstract class AbstractRepository {
*/
public function __construct(Client $client)
{
self::$client = $client;
$this->client = $client;
}

/**
Expand All @@ -42,7 +42,7 @@ public function __construct(Client $client)
*/
public function getClient()
{
return self::$client;
return $this->client;
}

/**
Expand Down
17 changes: 6 additions & 11 deletions test/Tmdb/Tests/Api/MoviesTest.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php
/**
* This file is part of the Wrike PHP API created by B-Found IM&S.
* 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 Wrike
* @author Michael Roterman <michael@b-found.nl>
* @copyright (c) 2013, B-Found Internet Marketing & Services
*
* @package Tmdb
* @author Michael Roterman <michael@wtfz.net>
* @copyright (c) 2013, Michael Roterman
* @version 0.0.1
*/
namespace Tmdb\Tests\Api;
Expand All @@ -28,6 +28,7 @@ public function shouldGetMovie()

$api->getMovie(self::MOVIE_ID);
}

/**
* @test
*/
Expand Down Expand Up @@ -80,7 +81,6 @@ public function shouldGetKeywords()
$api->getKeywords(self::MOVIE_ID);
}


/**
* @test
*/
Expand All @@ -94,7 +94,6 @@ public function getReleases()
$api->getReleases(self::MOVIE_ID);
}


/**
* @test
*/
Expand Down Expand Up @@ -134,7 +133,6 @@ public function shouldGetSimilarMovies()
$api->getSimilarMovies(self::MOVIE_ID);
}


/**
* @test
*/
Expand All @@ -148,7 +146,6 @@ public function shouldGetReviews()
$api->getReviews(self::MOVIE_ID);
}


/**
* @test
*/
Expand Down Expand Up @@ -201,7 +198,6 @@ public function shouldGetUpcoming()
$api->getUpcoming();
}


/**
* @test
*/
Expand All @@ -228,7 +224,6 @@ public function shouldGetPopular()
$api->getPopular();
}


/**
* @test
*/
Expand Down
16 changes: 10 additions & 6 deletions test/Tmdb/Tests/Api/TestCase.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php
/**
* This file is part of the Wrike PHP API created by B-Found IM&S.
* 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 Wrike
* @author Michael Roterman <michael@b-found.nl>
* @copyright (c) 2013, B-Found Internet Marketing & Services
*
* @package Tmdb
* @author Michael Roterman <michael@wtfz.net>
* @copyright (c) 2013, Michael Roterman
* @version 0.0.1
*/
namespace Tmdb\Tests\Api;
Expand All @@ -27,7 +27,11 @@ protected function getApiMock()
->expects($this->any())
->method('send');

$mock = $this->getMock('Tmdb\HttpClient\HttpClientInterface', array(), array(array(), $httpClient));
$mock = $this->getMock(
'Tmdb\HttpClient\HttpClientInterface',
array(),
array(array(), $httpClient)
);

$client = new \Tmdb\Client($token, $httpClient);
$client->setHttpClient($mock);
Expand Down
43 changes: 43 additions & 0 deletions test/Tmdb/Tests/Repository/MovieRepositoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?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\Repository;

class MovieRepositoryTest extends TestCase
{
const MOVIE_ID = 120;

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

$repository->getClient()->getHttpClient()->getClient()
->expects($this->once())
->method('send')
;

$repository->load(self::MOVIE_ID);
}

protected function getApiClass()
{
return 'Tmdb\Api\Movies';
}

protected function getRepositoryClass()
{
return 'Tmdb\Repository\MovieRepository';
}
}
55 changes: 55 additions & 0 deletions test/Tmdb/Tests/Repository/TestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?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\Repository;

use Guzzle\Http\Message\Response;
use Tmdb\ApiToken;
use Tmdb\Client;

abstract class TestCase extends \PHPUnit_Framework_TestCase
{
protected $repository;

abstract protected function getRepositoryClass();

protected function getRepositoryWithMockedClient()
{
$class = $this->getRepositoryClass();

return new $class($this->getMockedTmdbClient());
}

protected function getRepositoryMock($client = null, array $methods = array())
{
if ($client == null) {
$client = $this->getMockedTmdbClient();
}

return $this->getMock($this->getRepositoryClass(), array('getApi'), array($client));
}

protected function getMockedTmdbClient()
{
$token = new ApiToken('abcdef');
$response = new Response('200');

$httpClient = $this->getMock('Guzzle\Http\Client', array('send'));
$httpClient
->expects($this->any())
->method('send')
->will($this->returnValue($response))
;

return new Client($token, $httpClient);
}
}

0 comments on commit 38450c0

Please sign in to comment.