Skip to content

Commit

Permalink
Adding SearchRepositoryTest
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfzdotnet committed Feb 23, 2014
1 parent 56c161e commit 4c1f1b6
Show file tree
Hide file tree
Showing 2 changed files with 149 additions and 14 deletions.
37 changes: 23 additions & 14 deletions lib/Tmdb/Repository/SearchRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
use Tmdb\Model\Search\SearchQuery\MovieSearchQuery;
use Tmdb\Model\Search\SearchQuery\PersonSearchQuery;
use Tmdb\Model\Search\SearchQuery\TvSearchQuery;
use Tmdb\Model\Search\SearchQuery;
use Tmdb\Model\Tv;

class SearchRepository extends AbstractRepository {
Expand Down Expand Up @@ -94,8 +95,8 @@ public function __construct(Client $client)
*
* @return ResultCollection|Movie[]
*/
public function searchMovie($query, MovieSearchQuery $parameters = null, array $headers = array()) {
$data = $this->getApi()->searchMovies($query, $parameters->toArray(), $headers);
public function searchMovie($query, MovieSearchQuery $parameters, array $headers = array()) {
$data = $this->getApi()->searchMovies($query, $this->getParameters($parameters), $headers);

return $this->getMovieFactory()->createResultCollection($data);
}
Expand All @@ -107,8 +108,8 @@ public function searchMovie($query, MovieSearchQuery $parameters = null, array $
*
* @return ResultCollection|Collection[]
*/
public function searchCollection($query, CollectionSearchQuery $parameters = null, array $headers = array()) {
$data = $this->getApi()->searchCollection($query, $parameters->toArray(), $headers);
public function searchCollection($query, CollectionSearchQuery $parameters, array $headers = array()) {
$data = $this->getApi()->searchCollection($query, $this->getParameters($parameters), $headers);

return $this->getCollectionFactory()->createResultCollection($data);
}
Expand All @@ -120,8 +121,8 @@ public function searchCollection($query, CollectionSearchQuery $parameters = nul
*
* @return ResultCollection|Tv[]
*/
public function searchTv($query, TvSearchQuery $parameters = null, array $headers = array()) {
$data = $this->getApi()->searchTv($query, $parameters->toArray(), $headers);
public function searchTv($query, TvSearchQuery $parameters, array $headers = array()) {
$data = $this->getApi()->searchTv($query, $this->getParameters($parameters), $headers);

return $this->getTvFactory()->createResultCollection($data);
}
Expand All @@ -133,8 +134,8 @@ public function searchTv($query, TvSearchQuery $parameters = null, array $header
*
* @return ResultCollection|Person[]
*/
public function searchPerson($query, PersonSearchQuery $parameters = null, array $headers = array()) {
$data = $this->getApi()->searchPersons($query, $parameters->toArray(), $headers);
public function searchPerson($query, PersonSearchQuery $parameters, array $headers = array()) {
$data = $this->getApi()->searchPersons($query, $this->getParameters($parameters), $headers);

return $this->getPeopleFactory()->createResultCollection($data);
}
Expand All @@ -147,8 +148,8 @@ public function searchPerson($query, PersonSearchQuery $parameters = null, array
* @todo fix return docblock
* @return ResultCollection
*/
public function searchList($query, ListSearchQuery $parameters = null, array $headers = array()) {
$data = $this->getApi()->searchList($query, $parameters->toArray(), $headers);
public function searchList($query, ListSearchQuery $parameters, array $headers = array()) {
$data = $this->getApi()->searchList($query, $this->getParameters($parameters), $headers);

return $this->getListitemFactory()->createResultCollection($data);
}
Expand All @@ -160,8 +161,8 @@ public function searchList($query, ListSearchQuery $parameters = null, array $he
*
* @return ResultCollection|Company[]
*/
public function searchCompany($query, CompanySearchQuery $parameters = null, array $headers = array()) {
$data = $this->getApi()->searchTv($query, $parameters->toArray(), $headers);
public function searchCompany($query, CompanySearchQuery $parameters, array $headers = array()) {
$data = $this->getApi()->searchTv($query, $this->getParameters($parameters), $headers);

return $this->getCompanyFactory()->createResultCollection($data);
}
Expand All @@ -174,12 +175,20 @@ public function searchCompany($query, CompanySearchQuery $parameters = null, arr
*
* @return ResultCollection|Keyword[]
*/
public function searchKeyword($query, KeywordSearchQuery $parameters = null, array $headers = array()) {
$data = $this->getApi()->searchKeyword($query, $parameters->toArray(), $headers);
public function searchKeyword($query, KeywordSearchQuery $parameters, array $headers = array()) {
$data = $this->getApi()->searchKeyword($query, $this->getParameters($parameters), $headers);

return $this->getKeywordFactory()->createResultCollection($data);
}

private function getParameters($parameters = array()) {
if ($parameters instanceof SearchQuery) {
return $parameters->toArray();
}

return $parameters;
}

/**
* Return the related API class
*
Expand Down
126 changes: 126 additions & 0 deletions test/Tmdb/Tests/Repository/SearchRepositoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<?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 Tmdb\Model\Search\SearchQuery\CollectionSearchQuery;
use Tmdb\Model\Search\SearchQuery\CompanySearchQuery;
use Tmdb\Model\Search\SearchQuery\KeywordSearchQuery;
use Tmdb\Model\Search\SearchQuery\ListSearchQuery;
use Tmdb\Model\Search\SearchQuery\MovieSearchQuery;
use Tmdb\Model\Search\SearchQuery\PersonSearchQuery;
use Tmdb\Model\Search\SearchQuery\TvSearchQuery;
use Tmdb\Repository\SearchRepository;

class SearchRepositoryTest extends TestCase
{
/**
* @test
*/
public function shouldSearchMovie()
{
/**
* @var SearchRepository $repository
*/
$repository = $this->getRepositoryWithMockedHttpClient();

$repository->searchMovie('rush hour', new MovieSearchQuery());
}

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

$repository->searchCollection('the matrix', new CollectionSearchQuery());
}

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

$repository->searchTv('breaking bad', new TvSearchQuery());
}

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

$repository->searchPerson('johnny knoxville', new PersonSearchQuery());
}

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

$repository->searchList('golden', new ListSearchQuery());
}

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

$repository->searchCompany('disney', new CompanySearchQuery());
}

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

$repository->searchKeyword('alien', new KeywordSearchQuery());
}

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

protected function getRepositoryClass()
{
return 'Tmdb\Repository\SearchRepository';
}
}

0 comments on commit 4c1f1b6

Please sign in to comment.