diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 00000000..f85409d2 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,32 @@ + + + + + + ./test/Tmdb/ + + + + + + functional + + + + + + ./examples/ + ./lib/Tmdb/ + + + \ No newline at end of file diff --git a/test/Tmdb/Tests/Api/MoviesTest.php b/test/Tmdb/Tests/Api/MoviesTest.php new file mode 100644 index 00000000..44661477 --- /dev/null +++ b/test/Tmdb/Tests/Api/MoviesTest.php @@ -0,0 +1,248 @@ + + * @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'; + } +} \ No newline at end of file diff --git a/test/Tmdb/Tests/Api/TestCase.php b/test/Tmdb/Tests/Api/TestCase.php new file mode 100644 index 00000000..2272b167 --- /dev/null +++ b/test/Tmdb/Tests/Api/TestCase.php @@ -0,0 +1,40 @@ + + * @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(); + } +} \ No newline at end of file diff --git a/test/Tmdb/Tests/ClientTest.php b/test/Tmdb/Tests/ClientTest.php new file mode 100644 index 00000000..d2bcae9b --- /dev/null +++ b/test/Tmdb/Tests/ClientTest.php @@ -0,0 +1,25 @@ + + * @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()); + } +} \ No newline at end of file diff --git a/test/bootstrap.php b/test/bootstrap.php new file mode 100644 index 00000000..ab46da51 --- /dev/null +++ b/test/bootstrap.php @@ -0,0 +1,27 @@ + + * @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; \ No newline at end of file