From 54ddb3879a91ae67e379dd5c79ee2d3a3ed00dad Mon Sep 17 00:00:00 2001 From: Michael Roterman Date: Thu, 30 Jan 2014 00:19:47 +0100 Subject: [PATCH] Adding tests --- .../Model/Collection/ResultCollection.php | 6 +-- .../Query/Discover/DiscoverMoviesQuery.php | 2 +- .../Model/Query/Discover/DiscoverTvQuery.php | 2 +- .../Tests/Model/Query/ChangesQueryTest.php | 40 +++++++++++++++ .../Discover/DiscoverMoviesQueryTest.php | 51 +++++++++++++++++++ .../Query/Discover/DiscoverTvQueryTest.php | 47 +++++++++++++++++ 6 files changed, 143 insertions(+), 5 deletions(-) create mode 100644 test/Tmdb/Tests/Model/Query/ChangesQueryTest.php create mode 100644 test/Tmdb/Tests/Model/Query/Discover/DiscoverMoviesQueryTest.php create mode 100644 test/Tmdb/Tests/Model/Query/Discover/DiscoverTvQueryTest.php diff --git a/lib/Tmdb/Model/Collection/ResultCollection.php b/lib/Tmdb/Model/Collection/ResultCollection.php index 683c24d7..1b7bb00f 100644 --- a/lib/Tmdb/Model/Collection/ResultCollection.php +++ b/lib/Tmdb/Model/Collection/ResultCollection.php @@ -45,7 +45,7 @@ class ResultCollection extends GenericCollection { */ public function setPage($page) { - $this->page = $page; + $this->page = (int) $page; return $this; } @@ -63,7 +63,7 @@ public function getPage() */ public function setTotalPages($totalPages) { - $this->totalPages = $totalPages; + $this->totalPages = (int) $totalPages; return $this; } @@ -81,7 +81,7 @@ public function getTotalPages() */ public function setTotalResults($totalResults) { - $this->totalResults = $totalResults; + $this->totalResults = (int) $totalResults; return $this; } diff --git a/lib/Tmdb/Model/Query/Discover/DiscoverMoviesQuery.php b/lib/Tmdb/Model/Query/Discover/DiscoverMoviesQuery.php index 350a38ca..50a5f058 100644 --- a/lib/Tmdb/Model/Query/Discover/DiscoverMoviesQuery.php +++ b/lib/Tmdb/Model/Query/Discover/DiscoverMoviesQuery.php @@ -268,7 +268,7 @@ public function withCompanies($companies) */ public function withCompaniesAnd(array $companies = array()) { - return $this->withGenres( + return $this->withCompanies( implode(',', $companies) ); } diff --git a/lib/Tmdb/Model/Query/Discover/DiscoverTvQuery.php b/lib/Tmdb/Model/Query/Discover/DiscoverTvQuery.php index 544c8161..6ebd5550 100644 --- a/lib/Tmdb/Model/Query/Discover/DiscoverTvQuery.php +++ b/lib/Tmdb/Model/Query/Discover/DiscoverTvQuery.php @@ -208,7 +208,7 @@ public function withNetworks($networks) */ public function withNetworksAnd(array $networks = array()) { - return $this->withGenres( + return $this->withNetworks( implode(',', $networks) ); } diff --git a/test/Tmdb/Tests/Model/Query/ChangesQueryTest.php b/test/Tmdb/Tests/Model/Query/ChangesQueryTest.php new file mode 100644 index 00000000..751951ee --- /dev/null +++ b/test/Tmdb/Tests/Model/Query/ChangesQueryTest.php @@ -0,0 +1,40 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Tests\Model\Query; + +use Tmdb\Model\Query\ChangesQuery; +use Tmdb\Tests\TestCase; + +class ChangesQueryTest extends TestCase +{ + /** + * @test + */ + public function shouldCreateValidQuery() + { + $query = new ChangesQuery(); + + $now = new \DateTime(); + $tomorrow = new \DateTime('tomorrow'); + + $query + ->from($now) + ->to($tomorrow) + ->page(1) + ; + + $this->assertEquals($now->format('Y-m-d'), $query->get('from')); + $this->assertEquals($tomorrow->format('Y-m-d'), $query->get('to')); + $this->assertEquals(1, $query->get('page')); + } +} \ No newline at end of file diff --git a/test/Tmdb/Tests/Model/Query/Discover/DiscoverMoviesQueryTest.php b/test/Tmdb/Tests/Model/Query/Discover/DiscoverMoviesQueryTest.php new file mode 100644 index 00000000..4ee93427 --- /dev/null +++ b/test/Tmdb/Tests/Model/Query/Discover/DiscoverMoviesQueryTest.php @@ -0,0 +1,51 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Tests\Model\Query; + +use Tmdb\Model\Query\Discover\DiscoverMoviesQuery; +use Tmdb\Tests\TestCase; + +class DiscoverMoviesQueryTest extends TestCase +{ + /** + * @todo expand + * @test + */ + public function shouldCreateValidQuery() + { + $query = new DiscoverMoviesQuery(); + $now = new \DateTime(); + + $query + ->page(1) + ->language('en') + ->sortBy('sort') + ->includeAdult(false) + ->year($now) + ->primaryReleaseYear($now) + ->voteCountGte(5) + ->voteAverageGte(3) + ->withGenres(array(15,18)) + ->withGenresAnd(array(18)) + ->withGenresOr(array(1,2)) + ->releaseDateGte($now) + ->releaseDateLte($now) + ->certificationCountry('NL') + ->certificationLte(1) + ->withCompanies(array(1)) + ->withCompaniesAnd(array(2,5)) + ; + + $this->assertEquals(13, count($query)); + } +} \ No newline at end of file diff --git a/test/Tmdb/Tests/Model/Query/Discover/DiscoverTvQueryTest.php b/test/Tmdb/Tests/Model/Query/Discover/DiscoverTvQueryTest.php new file mode 100644 index 00000000..0a319aca --- /dev/null +++ b/test/Tmdb/Tests/Model/Query/Discover/DiscoverTvQueryTest.php @@ -0,0 +1,47 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Tests\Model\Query; + +use Tmdb\Model\Query\Discover\DiscoverTvQuery; +use Tmdb\Tests\TestCase; + +class DiscoverTvQueryTest extends TestCase +{ + /** + * @todo expand + * @test + */ + public function shouldCreateValidQuery() + { + $query = new DiscoverTvQuery(); + $now = new \DateTime(); + + $query + ->page(1) + ->language('en') + ->sortBy('sort') + ->firstAirDateYear($now) + ->voteCountGte(5) + ->voteAverageGte(3) + ->withGenres(array(15,18)) + ->withGenresOr(array(1,2)) + ->withGenresAnd(array(18)) + ->firstAirDateGte($now) + ->firstAirDateLte($now) + ->withNetworks(array(1,2)) + ->withNetworksAnd(array(1,2,3)) + ; + + $this->assertEquals(10, count($query)); + } +} \ No newline at end of file