diff --git a/lib/Tmdb/Factory/CompanyFactory.php b/lib/Tmdb/Factory/CompanyFactory.php index 213d180f..8cf215a4 100644 --- a/lib/Tmdb/Factory/CompanyFactory.php +++ b/lib/Tmdb/Factory/CompanyFactory.php @@ -16,11 +16,30 @@ class CompanyFactory extends AbstractFactory { + /** + * @var ImageFactory + */ + private $imageFactory; + + /** + * Constructor + */ + public function __construct() + { + $this->imageFactory = new ImageFactory(); + } + /** * {@inheritdoc} */ public function create(array $data = array()) { + $company = new Company(); + + if (array_key_exists('logo_path', $data)) { + $company->setLogo($this->getImageFactory()->createFromPath($data['logo_path'], 'logo_path')); + } + return $this->hydrate(new Company(), $data); } @@ -31,4 +50,22 @@ public function createCollection(array $data = array()) { return array(); } + + /** + * @param \Tmdb\Factory\ImageFactory $imageFactory + * @return $this + */ + public function setImageFactory($imageFactory) + { + $this->imageFactory = $imageFactory; + return $this; + } + + /** + * @return \Tmdb\Factory\ImageFactory + */ + public function getImageFactory() + { + return $this->imageFactory; + } } diff --git a/lib/Tmdb/Factory/FindFactory.php b/lib/Tmdb/Factory/FindFactory.php index ccc20111..427d6093 100644 --- a/lib/Tmdb/Factory/FindFactory.php +++ b/lib/Tmdb/Factory/FindFactory.php @@ -12,6 +12,7 @@ */ namespace Tmdb\Factory; +use Tmdb\Exception\NotImplementedException; use Tmdb\Model\Common\GenericCollection; use Tmdb\Model\Find; @@ -69,7 +70,7 @@ public function create(array $data = array()) */ public function createCollection(array $data = array()) { - return array(); + throw new NotImplementedException(sprintf('Method "%s" is not implemented.', __METHOD__)); } /** diff --git a/lib/Tmdb/Factory/GenreFactory.php b/lib/Tmdb/Factory/GenreFactory.php index 9e73b5f2..835376ad 100644 --- a/lib/Tmdb/Factory/GenreFactory.php +++ b/lib/Tmdb/Factory/GenreFactory.php @@ -32,8 +32,12 @@ public function createCollection(array $data = array()) { $collection = new Genres(); + if (array_key_exists('genres', $data)) { + $data = $data['genres']; + } + foreach($data as $item) { - $collection->addGenre($this->create((array) $item)); + $collection->addGenre($this->create($item)); } return $collection; diff --git a/lib/Tmdb/Factory/ImageFactory.php b/lib/Tmdb/Factory/ImageFactory.php index 10f05f86..8c05b3c4 100644 --- a/lib/Tmdb/Factory/ImageFactory.php +++ b/lib/Tmdb/Factory/ImageFactory.php @@ -28,12 +28,6 @@ public function create(array $data = array(), $key = null) { $type = self::resolveImageType($key); - if (is_string($data)) { - $data = array( - 'file_path' => $data - ); - } - return $this->hydrate($type, $data); } @@ -55,10 +49,12 @@ public function createFromPath($path, $key) } /** + * Helper function to obtain a new object for an image type + * * @param string|null $key * @return Image|Image\BackdropImage|Image\LogoImage|Image\PosterImage|Image\ProfileImage|Image\StillImage */ - private function resolveImageType($key = null) + public function resolveImageType($key = null) { switch($key) { case 'poster': diff --git a/lib/Tmdb/Factory/People/CastFactory.php b/lib/Tmdb/Factory/People/CastFactory.php index 6d5b3d57..87dd43f6 100644 --- a/lib/Tmdb/Factory/People/CastFactory.php +++ b/lib/Tmdb/Factory/People/CastFactory.php @@ -34,7 +34,7 @@ public function createCollection(array $data = array(), $person = null) $collection = new Cast(); foreach($data as $item) { - $collection->add(null, parent::create($item, $person)); + $collection->add(null, $this->create($item, $person)); } return $collection; diff --git a/lib/Tmdb/Factory/People/CrewFactory.php b/lib/Tmdb/Factory/People/CrewFactory.php index 067e80a4..deab2ffb 100644 --- a/lib/Tmdb/Factory/People/CrewFactory.php +++ b/lib/Tmdb/Factory/People/CrewFactory.php @@ -34,7 +34,7 @@ public function createCollection(array $data = array(), $person = null) $collection = new Crew(); foreach($data as $item) { - $collection->add(null, parent::create($item, $person)); + $collection->add(null, $this->create($item, $person)); } return $collection; diff --git a/lib/Tmdb/Repository/GenreRepository.php b/lib/Tmdb/Repository/GenreRepository.php index 8fdc402f..e86e51e3 100644 --- a/lib/Tmdb/Repository/GenreRepository.php +++ b/lib/Tmdb/Repository/GenreRepository.php @@ -49,17 +49,7 @@ public function loadCollection(array $parameters = array(), array $headers = arr * @return GenericCollection|Genre[] */ private function createCollection($data){ - $collection = new GenericCollection(); - - if (array_key_exists('genres', $data)) { - $data = $data['genres']; - } - - foreach($data as $item) { - $collection->add(null, $this->getFactory()->create($item)); - } - - return $collection; + return $this->getFactory()->createCollection($data); } /** diff --git a/lib/Tmdb/Repository/MovieRepository.php b/lib/Tmdb/Repository/MovieRepository.php index 869b1449..d776a04f 100644 --- a/lib/Tmdb/Repository/MovieRepository.php +++ b/lib/Tmdb/Repository/MovieRepository.php @@ -148,16 +148,6 @@ public function getTopRated(array $options = array()) * @return Movie[] */ private function createCollection($data){ - $collection = new GenericCollection(); - - if (array_key_exists('results', $data)) { - $data = $data['results']; - } - - foreach($data as $item) { - $collection->add(null, $this->getFactory()->create($item)); - } - - return $collection; + return $this->getFactory()->createCollection($data); } } diff --git a/lib/Tmdb/Repository/TvRepository.php b/lib/Tmdb/Repository/TvRepository.php index 10084831..1f980ddb 100644 --- a/lib/Tmdb/Repository/TvRepository.php +++ b/lib/Tmdb/Repository/TvRepository.php @@ -101,16 +101,6 @@ public function getTopRated(array $options = array()) * @return Tv[] */ private function createCollection($data){ - $collection = new GenericCollection(); - - if (array_key_exists('results', $data)) { - $data = $data['results']; - } - - foreach($data as $item) { - $collection->add(null, $this->getFactory()->create($item)); - } - - return $collection; + return $this->getFactory()->createCollection($data); } } diff --git a/test/Tmdb/Tests/Api/TestCase.php b/test/Tmdb/Tests/Api/TestCase.php index 68fb398b..2173bc8f 100644 --- a/test/Tmdb/Tests/Api/TestCase.php +++ b/test/Tmdb/Tests/Api/TestCase.php @@ -40,9 +40,4 @@ protected function getApiMock(array $methods = array()) ->setConstructorArgs(array($client)) ->getMock(); } - - protected function getMockedHttpClient() - { - return $this->getMock('Guzzle\Http\Client', array('send')); - } -} \ No newline at end of file +} diff --git a/test/Tmdb/Tests/Factory/CollectionFactoryTest.php b/test/Tmdb/Tests/Factory/CollectionFactoryTest.php index 3cbcf576..859f2c0c 100644 --- a/test/Tmdb/Tests/Factory/CollectionFactoryTest.php +++ b/test/Tmdb/Tests/Factory/CollectionFactoryTest.php @@ -55,6 +55,24 @@ public function shouldBeAbleToSetFactories() $this->assertInstanceOf('stdClass', $factory->getImageFactory()); } + + /** + * @test + */ + public function shouldBeAbleToCreateCollection() + { + $factory = $this->getFactory(); + + $data = array( + array('id' => 1), + array('id' => 2), + ); + + $collection = $factory->createCollection($data); + + $this->assertEquals(2, count($collection)); + } + protected function getFactoryClass() { return 'Tmdb\Factory\CollectionFactory'; diff --git a/test/Tmdb/Tests/Factory/CompanyFactoryTest.php b/test/Tmdb/Tests/Factory/CompanyFactoryTest.php index ddb4e976..7ce35e0f 100644 --- a/test/Tmdb/Tests/Factory/CompanyFactoryTest.php +++ b/test/Tmdb/Tests/Factory/CompanyFactoryTest.php @@ -88,6 +88,19 @@ public function callingCollectionReturnsEmptyArray() $this->assertEquals(array(), $collection); } + /** + * @test + */ + public function shouldBeAbleToSetFactories() + { + $factory = $this->getFactory(); + + $class = new \stdClass(); + $factory->setImageFactory($class); + + $this->assertInstanceOf('stdClass', $factory->getImageFactory()); + } + protected function getFactoryClass() { return 'Tmdb\Factory\CompanyFactory'; diff --git a/test/Tmdb/Tests/Factory/FindFactoryTest.php b/test/Tmdb/Tests/Factory/FindFactoryTest.php index 2eb50028..78165d3d 100644 --- a/test/Tmdb/Tests/Factory/FindFactoryTest.php +++ b/test/Tmdb/Tests/Factory/FindFactoryTest.php @@ -47,6 +47,34 @@ public function shouldConstructFind() } } + /** + * @test + */ + public function shouldBeAbleToSetFactories() + { + $factory = $this->getFactory(); + + $class = new \stdClass(); + + $factory->setMovieFactory($class); + $factory->setPeopleFactory($class); + $factory->setTvFactory($class); + + $this->assertInstanceOf('stdClass', $factory->getMovieFactory()); + $this->assertInstanceOf('stdClass', $factory->getPeopleFactory()); + $this->assertInstanceOf('stdClass', $factory->getTvFactory()); + } + + /** + * @test + * @expectedException Tmdb\Exception\NotImplementedException + */ + public function shouldThrowExceptionForCreateCollection() + { + $factory = $this->getFactory(); + $factory->createCollection(array()); + } + protected function getFactoryClass() { return 'Tmdb\Factory\FindFactory'; diff --git a/test/Tmdb/Tests/Factory/GenreFactoryTest.php b/test/Tmdb/Tests/Factory/GenreFactoryTest.php index 502a2448..e85b2769 100644 --- a/test/Tmdb/Tests/Factory/GenreFactoryTest.php +++ b/test/Tmdb/Tests/Factory/GenreFactoryTest.php @@ -83,6 +83,23 @@ public function shouldCollaborateWithCollection() $this->assertEquals(null, $genre); } + /** + * @test + */ + public function shouldBeAbleToDissectResults() + { + $factory = $this->getFactory(); + + $data = array('genres' => array( + array('id' => 1), + array('id' => 2), + )); + + $collection = $factory->createCollection($data); + + $this->assertEquals(2, count($collection)); + } + protected function getFactoryClass() { return 'Tmdb\Factory\GenreFactory'; diff --git a/test/Tmdb/Tests/Factory/ImageFactoryTest.php b/test/Tmdb/Tests/Factory/ImageFactoryTest.php index 10ddbcd6..950816b7 100644 --- a/test/Tmdb/Tests/Factory/ImageFactoryTest.php +++ b/test/Tmdb/Tests/Factory/ImageFactoryTest.php @@ -17,9 +17,18 @@ class ImageFactoryTest extends TestCase /** * @test */ - public function shouldConstructGenres() + public function shouldBeAbleToCreateCollection() { - $this->assertEquals(true,true); + $factory = $this->getFactory(); + + $data = array( + array('id' => 1), + array('id' => 2), + ); + + $collection = $factory->createCollection($data); + + $this->assertEquals(2, count($collection)); } protected function getFactoryClass() diff --git a/test/Tmdb/Tests/Factory/Movie/AlternativeTitleFactoryTest.php b/test/Tmdb/Tests/Factory/Movie/AlternativeTitleFactoryTest.php index 3c426531..d238fbd9 100644 --- a/test/Tmdb/Tests/Factory/Movie/AlternativeTitleFactoryTest.php +++ b/test/Tmdb/Tests/Factory/Movie/AlternativeTitleFactoryTest.php @@ -43,6 +43,24 @@ public function shouldConstructAlternativeTitle() $this->assertEquals('Kaas', $title->getTitle()); } + + /** + * @test + */ + public function shouldBeAbleToCreateCollection() + { + $factory = $this->getFactory(); + + $data = array( + array('id' => 1), + array('id' => 2), + ); + + $collection = $factory->createCollection($data); + + $this->assertEquals(2, count($collection)); + } + protected function getFactoryClass() { return 'Tmdb\Factory\Movie\AlternativeTitleFactory'; diff --git a/test/Tmdb/Tests/Factory/Movie/GenericCollectionFactoryTest.php b/test/Tmdb/Tests/Factory/Movie/GenericCollectionFactoryTest.php new file mode 100644 index 00000000..a4b6dd13 --- /dev/null +++ b/test/Tmdb/Tests/Factory/Movie/GenericCollectionFactoryTest.php @@ -0,0 +1,74 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Tests\Factory\Movie; + +use Tmdb\Factory\Common\GenericCollectionFactory; +use Tmdb\Factory\Movie\AlternativeTitleFactory; +use Tmdb\Model\AbstractModel; +use Tmdb\Model\Movie\AlternativeTitle; +use Tmdb\Tests\Factory\TestCase; + +class GenericCollectionFactoryTest extends TestCase +{ + + /** + * @test + */ + public function shouldBeAbleToCreateCollection() + { + $factory = $this->getFactory(); + + $data = array( + array('id' => 2), + array('id' => 2), + ); + + $collection = $factory->create($data, new FakeClass()); + + $this->assertEquals(2, count($collection)); + + foreach($collection as $item) { + $this->assertEquals(2, $item->getId()); + } + } + + protected function getFactoryClass() + { + return 'Tmdb\Factory\Common\GenericCollectionFactory'; + } +} + +class FakeClass extends AbstractModel { + + public static $_properties = array('id'); + + private $id; + + /** + * @param mixed $id + * @return $this + */ + public function setId($id) + { + $this->id = $id; + return $this; + } + + /** + * @return mixed + */ + public function getId() + { + return $this->id; + } +} diff --git a/test/Tmdb/Tests/Factory/MovieFactoryTest.php b/test/Tmdb/Tests/Factory/MovieFactoryTest.php index c0b430d2..8ce0b71c 100644 --- a/test/Tmdb/Tests/Factory/MovieFactoryTest.php +++ b/test/Tmdb/Tests/Factory/MovieFactoryTest.php @@ -83,7 +83,7 @@ public function shouldBeFunctional() $this->assertEquals('/1NfhdnQAEqcBRCulEhOFSkRrrLv.jpg', $this->movie->getPosterPath()); $this->assertInstanceOf('Tmdb\Model\Common\GenericCollection', $this->movie->getProductionCompanies()); $this->assertInstanceOf('Tmdb\Model\Common\GenericCollection', $this->movie->getProductionCountries()); - // release + // @todo release $this->assertEquals(42025135, $this->movie->getRevenue()); $this->assertEquals(119, $this->movie->getRuntime()); $this->assertInstanceOf('Tmdb\Model\Common\GenericCollection', $this->movie->getSpokenLanguages()); @@ -102,6 +102,23 @@ public function shouldBeFunctional() $this->assertInstanceOf('Tmdb\Model\Common\GenericCollection', $this->movie->getTrailers()); } + /** + * @test + */ + public function shouldBeAbleToDissectResults() + { + $factory = $this->getFactory(); + + $data = array('results' => array( + array('id' => 1), + array('id' => 2), + )); + + $collection = $factory->createCollection($data); + + $this->assertEquals(2, count($collection)); + } + protected function getFactoryClass() { return 'Tmdb\Factory\MovieFactory'; diff --git a/test/Tmdb/Tests/Factory/PeopleFactoryTest.php b/test/Tmdb/Tests/Factory/PeopleFactoryTest.php index 298993aa..534248ad 100644 --- a/test/Tmdb/Tests/Factory/PeopleFactoryTest.php +++ b/test/Tmdb/Tests/Factory/PeopleFactoryTest.php @@ -67,6 +67,36 @@ public function shouldConstructCastAndCredits() $this->assertInstanceOf('Tmdb\Model\Collection\People\Crew', $crew); } + /** + * @test + */ + public function shouldBeAbleToSetImageFactory() + { + $factory = $this->getFactory(); + + $newFactory = new \stdClass(); + $factory->setImageFactory($newFactory); + + $this->assertInstanceOf('\stdClass', $factory->getImageFactory()); + } + + /** + * @test + */ + public function shouldBeAbleToDissectResults() + { + $factory = $this->getFactory(); + + $data = array('results' => array( + array('id' => 1), + array('id' => 2), + )); + + $collection = $factory->createCollection($data); + + $this->assertEquals(2, count($collection)); + } + protected function getFactoryClass() { return 'Tmdb\Factory\PeopleFactory'; diff --git a/test/Tmdb/Tests/Factory/TvFactoryTest.php b/test/Tmdb/Tests/Factory/TvFactoryTest.php index 608a1d3f..eda53f99 100644 --- a/test/Tmdb/Tests/Factory/TvFactoryTest.php +++ b/test/Tmdb/Tests/Factory/TvFactoryTest.php @@ -64,6 +64,24 @@ public function shouldBeAbleToSetFactories() $this->assertInstanceOf('stdClass', $factory->getTvSeasonFactory()); } + + /** + * @test + */ + public function shouldBeAbleToDissectResults() + { + $factory = $this->getFactory(); + + $data = array('results' => array( + array('id' => 1), + array('id' => 2), + )); + + $collection = $factory->createCollection($data); + + $this->assertEquals(2, count($collection)); + } + protected function getFactoryClass() { return 'Tmdb\Factory\TvFactory'; diff --git a/test/Tmdb/Tests/HttpClient/HttpClientTest.php b/test/Tmdb/Tests/HttpClient/HttpClientTest.php new file mode 100644 index 00000000..014ea535 --- /dev/null +++ b/test/Tmdb/Tests/HttpClient/HttpClientTest.php @@ -0,0 +1,211 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Tests\HttpClient; + +use Guzzle\Common\Event; +use Tmdb\HttpClient\HttpClient; +use Tmdb\Tests\TestCase; + +class HttpClientTest extends TestCase +{ + /** + * @var \Guzzle\Http\Client + */ + private $guzzleMock; + + /** + * @var TestApi + */ + private $testApi; + + /** + * @var HttpClient + */ + private $client; + + public function setUp() + { + $this->guzzleMock = $this->getMockBuilder('Guzzle\Http\Client') + ->setConstructorArgs(array('http://www.google.com/', array())) + ->setMethods(array()) + ->getMock(); + + $this->client = new HttpClient('http://www.google.com', array(), $this->guzzleMock); + $this->testApi = new TestApi($this->client); + } + + /** + * @test + */ + public function shouldCallGet() + { + $this->setUp(); + + $this->guzzleMock + ->expects($this->once()) + ->method('get') + ->will($this->returnValue($this->getMock('Guzzle\Http\Message\RequestInterface'))) + ; + + $this->testApi->get('/'); + } + + /** + * @test + */ + public function shouldCallHead() + { + $this->setUp(); + + $this->guzzleMock + ->expects($this->once()) + ->method('head') + ->will($this->returnValue($this->getMock('Guzzle\Http\Message\RequestInterface'))) + ; + + $this->testApi->head('/'); + } + + /** + * @test + */ + public function shouldCallPost() + { + $this->setUp(); + + $this->guzzleMock + ->expects($this->once()) + ->method('post') + ->will($this->returnValue($this->getMock('Guzzle\Http\Message\RequestInterface'))) + ; + + $this->testApi->post('/', array('name' => 'Henk')); + } + + /** + * @test + */ + public function shouldCallPatch() + { + $this->setUp(); + + $this->guzzleMock + ->expects($this->once()) + ->method('patch') + ->will($this->returnValue($this->getMock('Guzzle\Http\Message\RequestInterface'))) + ; + + $this->testApi->patch('/'); + } + + /** + * @test + */ + public function shouldCallDelete() + { + $this->setUp(); + + $this->guzzleMock + ->expects($this->once()) + ->method('delete') + ->will($this->returnValue($this->getMock('Guzzle\Http\Message\RequestInterface'))) + ; + + $this->testApi->delete('/'); + } + + + /** + * @test + */ + public function put() + { + $this->setUp(); + + $this->guzzleMock + ->expects($this->once()) + ->method('put') + ->will($this->returnValue($this->getMock('Guzzle\Http\Message\RequestInterface'))) + ; + + $this->testApi->put('/'); + } + + /** + * @test + */ + public function shouldRegisterSubscribers() + { + $this->setUp(); + + $this->guzzleMock + ->expects($this->once()) + ->method('addSubscriber') + ; + + $event = $this->getMock('Symfony\Component\EventDispatcher\EventSubscriberInterface'); + $this->testApi->addSubscriber($event); + } + + /** + * @test + */ + public function shouldBeAbleToOverrideClient() + { + $httpClient = new HttpClient('http://google.nl', array(), new \Guzzle\Http\Client()); + + $httpClient->setClient(new \stdClass()); + + $this->assertInstanceOf('stdClass', $httpClient->getClient()); + } +} + +class TestApi { + /** + * @var \Tmdb\HttpClient\HttpClient + */ + private $client; + + public function __construct($client) + { + $this->client = $client; + } + + public function get() { + $this->client->get('/'); + } + + public function head() { + $this->client->head('/'); + } + + public function post() { + $this->client->post('/', array('id' => 1)); + } + + public function patch() { + $this->client->patch('http://www.google.com/'); + } + + public function delete() { + $this->client->delete('http://www.google.com/'); + } + + public function put() { + $this->client->put('http://www.google.com/'); + } + + public function addSubscriber($event) { + $this->client->addSubscriber($event); + } +} diff --git a/test/Tmdb/Tests/Repository/DiscoverRepositoryTest.php b/test/Tmdb/Tests/Repository/DiscoverRepositoryTest.php index e7e8fec2..30912606 100644 --- a/test/Tmdb/Tests/Repository/DiscoverRepositoryTest.php +++ b/test/Tmdb/Tests/Repository/DiscoverRepositoryTest.php @@ -30,6 +30,31 @@ public function shouldDiscoverMovies() $repository->discoverMovies($query); } + /** + * @test + * @expectedException Tmdb\Exception\RuntimeException + */ + public function shouldThrowExceptionWhenCertificationCountryIssetButCertificationLteIsNot() + { + $repository = $this->getRepositoryWithMockedHttpClient(); + + $query = new DiscoverMoviesQuery(); + $query->certificationCountry('nl'); + + $repository->discoverMovies($query); + } + + /** + * @test + * @expectedException Tmdb\Exception\NotImplementedException + */ + public function shouldThrowExceptionForGetFactory() + { + $repository = $this->getRepositoryWithMockedHttpClient(); + + $repository->getFactory(); + } + /** * @test */ diff --git a/test/Tmdb/Tests/Repository/GenreRepositoryTest.php b/test/Tmdb/Tests/Repository/GenreRepositoryTest.php index 84a94864..349553fe 100644 --- a/test/Tmdb/Tests/Repository/GenreRepositoryTest.php +++ b/test/Tmdb/Tests/Repository/GenreRepositoryTest.php @@ -36,6 +36,16 @@ public function shouldLoadCollection() $repository->loadCollection(); } + /** + * @test + */ + public function shouldGetFactory() + { + $repository = $this->getRepositoryWithMockedHttpClient(); + + $this->assertInstanceOf('Tmdb\Factory\GenreFactory', $repository->getFactory()); + } + protected function getApiClass() { return 'Tmdb\Api\Genres'; diff --git a/test/Tmdb/Tests/Repository/TestCase.php b/test/Tmdb/Tests/Repository/TestCase.php index 5530c9c8..aa1e0ebf 100644 --- a/test/Tmdb/Tests/Repository/TestCase.php +++ b/test/Tmdb/Tests/Repository/TestCase.php @@ -39,19 +39,4 @@ protected function getRepositoryMock($client = null, array $methods = array()) return $this->getMock($this->getRepositoryClass(), array_merge(array('getApi'), $methods), 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); - } } \ No newline at end of file diff --git a/test/Tmdb/Tests/TestCase.php b/test/Tmdb/Tests/TestCase.php index 45a2049f..e4f3ad08 100644 --- a/test/Tmdb/Tests/TestCase.php +++ b/test/Tmdb/Tests/TestCase.php @@ -12,7 +12,9 @@ */ namespace Tmdb\Tests; +use Guzzle\Http\Message\Response; use Tmdb\ApiToken; +use Tmdb\Client; use Tmdb\Common\ObjectHydrator; abstract class TestCase extends \PHPUnit_Framework_TestCase @@ -86,6 +88,40 @@ protected function getClientWithMockedHttpClient() return $client; } + /** + * Get TMDB Client + * + * @return 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); + } + + /** + * Get mocked http client + * + * @param array $methods + * @return \PHPUnit_Framework_MockObject_MockObject + */ + protected function getMockedHttpClient(array $methods = array()) + { + return $this->getMock('Guzzle\Http\Client', array_merge( + $methods, + array('send') + )); + } + /** * Hydrate object *