Skip to content

Commit

Permalink
Adding tests for Api\Movies
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfzdotnet committed Jan 22, 2014
1 parent d43d291 commit 22cf331
Show file tree
Hide file tree
Showing 5 changed files with 372 additions and 0 deletions.
32 changes: 32 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="test/bootstrap.php"
>
<testsuites>
<testsuite name="php-tmdb-api Test Suite">
<directory>./test/Tmdb/</directory>
</testsuite>
</testsuites>

<groups>
<exclude>
<group>functional</group>
</exclude>
</groups>

<filter>
<whitelist>
<directory suffix=".php">./examples/</directory>
<directory suffix=".php">./lib/Tmdb/</directory>
</whitelist>
</filter>
</phpunit>
248 changes: 248 additions & 0 deletions test/Tmdb/Tests/Api/MoviesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,248 @@
<?php
/**
* This file is part of the Wrike PHP API created by B-Found IM&S.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @package Wrike
* @author Michael Roterman <[email protected]>
* @copyright (c) 2013, B-Found Internet Marketing & Services
* @version 0.0.1
*/
namespace Tmdb\Tests\Api;

class MoviesTest extends TestCase
{
const MOVIE_ID = 120;

/**
* @test
*/
public function shouldGetMovie()
{
$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('movie/' . self::MOVIE_ID);

$api->getMovie(self::MOVIE_ID);
}
/**
* @test
*/
public function shouldGetAlternativeTitles()
{
$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('movie/' . self::MOVIE_ID . '/alternative_titles');

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

/**
* @test
*/
public function shouldGetCast()
{
$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('movie/' . self::MOVIE_ID . '/casts');

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

/**
* @test
*/
public function shouldGetImages()
{
$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('movie/' . self::MOVIE_ID . '/images');

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

/**
* @test
*/
public function shouldGetKeywords()
{
$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('movie/' . self::MOVIE_ID . '/keywords');

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


/**
* @test
*/
public function getReleases()
{
$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('movie/' . self::MOVIE_ID . '/releases');

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


/**
* @test
*/
public function shouldGetTrailers()
{
$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('movie/' . self::MOVIE_ID . '/trailers');

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

/**
* @test
*/
public function shouldGetTranslations()
{
$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('movie/' . self::MOVIE_ID . '/translations');

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

/**
* @test
*/
public function shouldGetSimilarMovies()
{
$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('movie/' . self::MOVIE_ID . '/similar_movies');

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


/**
* @test
*/
public function shouldGetReviews()
{
$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('movie/' . self::MOVIE_ID . '/reviews');

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


/**
* @test
*/
public function shouldGetLists()
{
$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('movie/' . self::MOVIE_ID . '/lists');

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

/**
* @test
*/
public function shouldGetChanges()
{
$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('movie/' . self::MOVIE_ID . '/changes');

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

/**
* @test
*/
public function shouldGetLatest()
{
$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('movie/latest');

$api->getLatest();
}

/**
* @test
*/
public function shouldGetUpcoming()
{
$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('movie/upcoming');

$api->getUpcoming();
}


/**
* @test
*/
public function shouldGetNowPlaying()
{
$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('movie/now_playing');

$api->getNowPlaying();
}

/**
* @test
*/
public function shouldGetPopular()
{
$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('movie/popular');

$api->getPopular();
}


/**
* @test
*/
public function shouldGetTopRated()
{
$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('movie/top_rated');

$api->getTopRated();
}

protected function getApiClass() {
return 'Tmdb\Api\Movies';
}
}
40 changes: 40 additions & 0 deletions test/Tmdb/Tests/Api/TestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
/**
* This file is part of the Wrike PHP API created by B-Found IM&S.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @package Wrike
* @author Michael Roterman <[email protected]>
* @copyright (c) 2013, B-Found Internet Marketing & Services
* @version 0.0.1
*/
namespace Tmdb\Tests\Api;

use Tmdb\ApiToken;

abstract class TestCase extends \PHPUnit_Framework_TestCase
{
abstract protected function getApiClass();

protected function getApiMock()
{
$token = new ApiToken('abcdef');

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

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

$client = new \Tmdb\Client($token, $httpClient);
$client->setHttpClient($mock);

return $this->getMockBuilder($this->getApiClass())
->setMethods(array('get', 'post', 'postRaw', 'patch', 'delete', 'put'))
->setConstructorArgs(array($client))
->getMock();
}
}
25 changes: 25 additions & 0 deletions test/Tmdb/Tests/ClientTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?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
*/
class ClientTest extends \PHPUnit_Framework_TestCase
{
/**
* @test
*/
public function shouldNotHaveToPassHttpClientToConstructor()
{
$token = new \Tmdb\ApiToken('abcdef');
$client = new \Tmdb\Client($token);

$this->assertInstanceOf('Tmdb\HttpClient\HttpClient', $client->getHttpClient());
}
}
27 changes: 27 additions & 0 deletions test/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?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
*/
function includeIfExists($file) {
if (file_exists($file)) {
return include $file;
}
}

if ((!$loader = includeIfExists(__DIR__.'/../vendor/autoload.php')) && (!$loader = includeIfExists(__DIR__.'/../../../.composer/autoload.php'))) {
die('You must set up the project dependencies, run the following commands:'.PHP_EOL.
'curl -s http://getcomposer.org/installer | php'.PHP_EOL.
'php composer.phar install'.PHP_EOL);
}

$loader->add('Tmdb\Tests', __DIR__);

return $loader;

0 comments on commit 22cf331

Please sign in to comment.