From 92c978e2552bef06a103067e9c5307f17823eea0 Mon Sep 17 00:00:00 2001 From: Michael Roterman Date: Sun, 25 Jan 2015 15:45:16 +0100 Subject: [PATCH 1/2] Adding events at hydration. --- lib/Tmdb/Client.php | 10 ++ lib/Tmdb/Event/HydrationEvent.php | 137 ++++++++++++++++++ lib/Tmdb/Event/HydrationSubscriber.php | 72 +++++++++ lib/Tmdb/Event/TmdbEvents.php | 6 + lib/Tmdb/Factory/AbstractFactory.php | 43 +++++- lib/Tmdb/Factory/AccountFactory.php | 16 +- lib/Tmdb/Factory/CollectionFactory.php | 11 +- lib/Tmdb/Factory/CompanyFactory.php | 9 +- lib/Tmdb/Factory/CreditsFactory.php | 16 +- lib/Tmdb/Factory/FindFactory.php | 13 +- lib/Tmdb/Factory/ImageFactory.php | 6 +- lib/Tmdb/Factory/ListFactory.php | 14 +- lib/Tmdb/Factory/Lists/ListItemFactory.php | 12 +- lib/Tmdb/Factory/Movie/ListItemFactory.php | 15 +- lib/Tmdb/Factory/MovieFactory.php | 25 ++-- lib/Tmdb/Factory/People/CastFactory.php | 11 ++ lib/Tmdb/Factory/People/CrewFactory.php | 11 ++ lib/Tmdb/Factory/PeopleFactory.php | 11 +- lib/Tmdb/Factory/TvEpisodeFactory.php | 19 ++- lib/Tmdb/Factory/TvFactory.php | 27 ++-- lib/Tmdb/Factory/TvSeasonFactory.php | 20 ++- lib/Tmdb/HttpClient/HttpClient.php | 12 +- lib/Tmdb/Repository/AbstractRepository.php | 15 +- lib/Tmdb/Repository/AccountRepository.php | 2 +- .../Repository/AuthenticationRepository.php | 2 +- .../Repository/CertificationRepository.php | 2 +- lib/Tmdb/Repository/ChangesRepository.php | 2 +- lib/Tmdb/Repository/CollectionRepository.php | 4 +- lib/Tmdb/Repository/CompanyRepository.php | 4 +- .../Repository/ConfigurationRepository.php | 2 +- lib/Tmdb/Repository/CreditsRepository.php | 2 +- lib/Tmdb/Repository/DiscoverRepository.php | 4 +- lib/Tmdb/Repository/FindRepository.php | 2 +- lib/Tmdb/Repository/GenreRepository.php | 2 +- .../Repository/GuestSessionRepository.php | 4 +- lib/Tmdb/Repository/JobsRepository.php | 2 +- lib/Tmdb/Repository/KeywordRepository.php | 2 +- lib/Tmdb/Repository/ListRepository.php | 2 +- lib/Tmdb/Repository/MovieRepository.php | 2 +- lib/Tmdb/Repository/NetworkRepository.php | 2 +- lib/Tmdb/Repository/PeopleRepository.php | 4 +- lib/Tmdb/Repository/ReviewRepository.php | 2 +- lib/Tmdb/Repository/SearchRepository.php | 14 +- lib/Tmdb/Repository/TimezoneRepository.php | 2 +- lib/Tmdb/Repository/TvEpisodeRepository.php | 5 +- lib/Tmdb/Repository/TvRepository.php | 2 +- lib/Tmdb/Repository/TvSeasonRepository.php | 5 +- test/Tmdb/Tests/Api/GuestSessionTest.php | 5 +- test/Tmdb/Tests/Factory/PeopleFactoryTest.php | 2 +- test/Tmdb/Tests/Factory/TestCase.php | 19 ++- test/Tmdb/Tests/Factory/TvFactoryTest.php | 2 +- test/Tmdb/Tests/Helper/ImageHelperTest.php | 6 +- test/Tmdb/Tests/Model/ImageTest.php | 6 +- .../Repository/GuestSessionRepositoryTest.php | 5 +- .../Repository/TvEpisodeRepositoryTest.php | 4 +- .../Repository/TvSeasonRepositoryTest.php | 4 +- 56 files changed, 532 insertions(+), 128 deletions(-) create mode 100644 lib/Tmdb/Event/HydrationEvent.php create mode 100644 lib/Tmdb/Event/HydrationSubscriber.php diff --git a/lib/Tmdb/Client.php b/lib/Tmdb/Client.php index 3b1c2e87..10a151bd 100644 --- a/lib/Tmdb/Client.php +++ b/lib/Tmdb/Client.php @@ -124,6 +124,16 @@ public function getAdapter() return $this->options['adapter']; } + /** + * Get the event dispatcher + * + * @return AdapterInterface + */ + public function getEventDispatcher() + { + return $this->options['event_dispatcher']; + } + /** * @return array */ diff --git a/lib/Tmdb/Event/HydrationEvent.php b/lib/Tmdb/Event/HydrationEvent.php new file mode 100644 index 00000000..261a7a40 --- /dev/null +++ b/lib/Tmdb/Event/HydrationEvent.php @@ -0,0 +1,137 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Event; + +use Symfony\Component\EventDispatcher\Event; +use Tmdb\HttpClient\Request; +use Tmdb\HttpClient\Response; +use Tmdb\Model\AbstractModel; + +class HydrationEvent extends Event +{ + /** + * @var AbstractModel + */ + private $subject; + + /** + * @var array + */ + private $data; + + /** + * @var Request|null + */ + private $lastRequest; + + /** + * @var Response|null + */ + private $lastResponse; + + /** + * Constructor + * + * @param AbstractModel $subject + * @param array $data + */ + public function __construct(AbstractModel $subject, array $data = []) + { + $this->subject = $subject; + $this->data = $data; + } + + /** + * @return AbstractModel + */ + public function getSubject() + { + return $this->subject; + } + + /** + * @param AbstractModel $subject + * @return $this + */ + public function setSubject($subject) + { + $this->subject = $subject; + + return $this; + } + + /** + * @return array + */ + public function getData() + { + return $this->data; + } + + /** + * @param array $data + * @return $this + */ + public function setData($data) + { + $this->data = $data; + + return $this; + } + + /** + * @return bool + */ + public function hasData() + { + return !empty($this->data); + } + + /** + * @return Request + */ + public function getLastRequest() + { + return $this->lastRequest; + } + + /** + * @param Request|null $lastRequest + * @return $this + */ + public function setLastRequest($lastRequest) + { + $this->lastRequest = $lastRequest; + + return $this; + } + + /** + * @return Response + */ + public function getLastResponse() + { + return $this->lastResponse; + } + + /** + * @param Response|null $lastResponse + * @return $this + */ + public function setLastResponse($lastResponse) + { + $this->lastResponse = $lastResponse; + + return $this; + } +} diff --git a/lib/Tmdb/Event/HydrationSubscriber.php b/lib/Tmdb/Event/HydrationSubscriber.php new file mode 100644 index 00000000..b9108ba1 --- /dev/null +++ b/lib/Tmdb/Event/HydrationSubscriber.php @@ -0,0 +1,72 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Event; + +use Tmdb\Common\ObjectHydrator; +use Tmdb\HttpClient\HttpClientEventSubscriber; + +/** + * Class RequestSubscriber + * @package Tmdb\Event + */ +class HydrationSubscriber extends HttpClientEventSubscriber +{ + /** + * Get subscribed events + * + * @return array + */ + public static function getSubscribedEvents() + { + return [ + TmdbEvents::HYDRATE => 'hydrate', + ]; + } + + /** + * Hydrate the subject with data + * + * @param HydrationEvent $event + * @return \Tmdb\Model\AbstractModel + */ + public function hydrate(HydrationEvent $event) + { + // Possibility to load serialized cache + $event->getDispatcher()->dispatch(TmdbEvents::BEFORE_HYDRATION, $event); + + if ($event->isPropagationStopped()) { + return $event->getSubject(); + } + + $subject = $this->hydrateSubject($event); + $event->setSubject($subject); + + // Possibility to cache the data + $event->getDispatcher()->dispatch(TmdbEvents::AFTER_HYDRATION, $event); + + return $event->getSubject(); + } + + /** + * Hydrate the subject + * + * @param HydrationEvent $event + * @return \Tmdb\Model\AbstractModel + */ + public function hydrateSubject(HydrationEvent $event) + { + $objectHydrator = new ObjectHydrator(); + + return $objectHydrator->hydrate($event->getSubject(), $event->getData()); + } +} diff --git a/lib/Tmdb/Event/TmdbEvents.php b/lib/Tmdb/Event/TmdbEvents.php index eb46c14d..34426cc9 100644 --- a/lib/Tmdb/Event/TmdbEvents.php +++ b/lib/Tmdb/Event/TmdbEvents.php @@ -14,7 +14,13 @@ final class TmdbEvents { + /** Request */ const BEFORE_REQUEST = 'tmdb.before_request'; const REQUEST = 'tmdb.request'; const AFTER_REQUEST = 'tmdb.after_request'; + + /** Hydration */ + const BEFORE_HYDRATION = 'tmdb.before_hydration'; + const HYDRATE = 'tmdb.hydrate'; + const AFTER_HYDRATION = 'tmdb.after_hydration'; } diff --git a/lib/Tmdb/Factory/AbstractFactory.php b/lib/Tmdb/Factory/AbstractFactory.php index 9133e96a..eb38b8b5 100644 --- a/lib/Tmdb/Factory/AbstractFactory.php +++ b/lib/Tmdb/Factory/AbstractFactory.php @@ -12,7 +12,9 @@ */ namespace Tmdb\Factory; -use Tmdb\Common\ObjectHydrator; +use Tmdb\Event\HydrationEvent; +use Tmdb\Event\TmdbEvents; +use Tmdb\HttpClient\HttpClient; use Tmdb\Model\AbstractModel; use Tmdb\Model\Collection\ResultCollection; use Tmdb\Model\Common\AccountStates; @@ -26,6 +28,21 @@ */ abstract class AbstractFactory { + /** + * @var HttpClient + */ + protected $httpClient; + + /** + * Constructor + * + * @param HttpClient $httpClient + */ + public function __construct(HttpClient $httpClient) + { + $this->httpClient = $httpClient; + } + /** * Convert an array to an hydrated object * @@ -42,6 +59,16 @@ abstract public function create(array $data = []); */ abstract public function createCollection(array $data = []); + /** + * Get the http client + * + * @return HttpClient + */ + protected function getHttpClient() + { + return $this->httpClient; + } + /** * Create a generic collection of data and map it on the class by it's static parameter $properties * @@ -179,14 +206,20 @@ public function createResult(array $data = []) /** * Hydrate the object with data * - * @param AbstractModel $object + * @param AbstractModel $subject * @param array $data * @return AbstractModel */ - protected function hydrate(AbstractModel $object, $data = []) + protected function hydrate(AbstractModel $subject, $data = []) { - $objectHydrator = new ObjectHydrator(); + $httpClient = $this->getHttpClient(); + + $event = new HydrationEvent($subject, $data); + $event->setLastRequest($httpClient->getLastRequest()); + $event->setLastResponse($httpClient->getLastResponse()); + + $this->getHttpClient()->getEventDispatcher()->dispatch(TmdbEvents::HYDRATE, $event); - return $objectHydrator->hydrate($object, $data); + return $event->getSubject(); } } diff --git a/lib/Tmdb/Factory/AccountFactory.php b/lib/Tmdb/Factory/AccountFactory.php index 672762d2..696c226f 100644 --- a/lib/Tmdb/Factory/AccountFactory.php +++ b/lib/Tmdb/Factory/AccountFactory.php @@ -12,6 +12,7 @@ */ namespace Tmdb\Factory; +use Tmdb\HttpClient\HttpClient; use Tmdb\Model\Account; use Tmdb\Model\Lists\Result; @@ -36,11 +37,18 @@ class AccountFactory extends AbstractFactory */ private $tvFactory; - public function __construct() + /** + * Constructor + * + * @param HttpClient $httpClient + */ + public function __construct(HttpClient $httpClient) { - $this->movieFactory = new MovieFactory(); - $this->imageFactory = new ImageFactory(); - $this->tvFactory = new TvFactory(); + $this->movieFactory = new MovieFactory($httpClient); + $this->imageFactory = new ImageFactory($httpClient); + $this->tvFactory = new TvFactory($httpClient); + + parent::__construct($httpClient); } /** diff --git a/lib/Tmdb/Factory/CollectionFactory.php b/lib/Tmdb/Factory/CollectionFactory.php index 1f4bfc79..a0f03ec1 100644 --- a/lib/Tmdb/Factory/CollectionFactory.php +++ b/lib/Tmdb/Factory/CollectionFactory.php @@ -12,6 +12,7 @@ */ namespace Tmdb\Factory; +use Tmdb\HttpClient\HttpClient; use Tmdb\Model\Collection; use Tmdb\Model\Common\GenericCollection; @@ -33,11 +34,15 @@ class CollectionFactory extends AbstractFactory /** * Constructor + * + * @param HttpClient $httpClient */ - public function __construct() + public function __construct(HttpClient $httpClient) { - $this->movieFactory = new MovieFactory(); - $this->imageFactory = new ImageFactory(); + $this->movieFactory = new MovieFactory($httpClient); + $this->imageFactory = new ImageFactory($httpClient); + + parent::__construct($httpClient); } /** diff --git a/lib/Tmdb/Factory/CompanyFactory.php b/lib/Tmdb/Factory/CompanyFactory.php index 40fc26e7..05488cc4 100644 --- a/lib/Tmdb/Factory/CompanyFactory.php +++ b/lib/Tmdb/Factory/CompanyFactory.php @@ -12,6 +12,7 @@ */ namespace Tmdb\Factory; +use Tmdb\HttpClient\HttpClient; use Tmdb\Model\Common\GenericCollection; use Tmdb\Model\Company; @@ -28,10 +29,14 @@ class CompanyFactory extends AbstractFactory /** * Constructor + * + * @param HttpClient $httpClient */ - public function __construct() + public function __construct(HttpClient $httpClient) { - $this->imageFactory = new ImageFactory(); + $this->imageFactory = new ImageFactory($httpClient); + + parent::__construct($httpClient); } /** diff --git a/lib/Tmdb/Factory/CreditsFactory.php b/lib/Tmdb/Factory/CreditsFactory.php index 1b776998..09743eb4 100644 --- a/lib/Tmdb/Factory/CreditsFactory.php +++ b/lib/Tmdb/Factory/CreditsFactory.php @@ -13,6 +13,7 @@ namespace Tmdb\Factory; use Tmdb\Exception\NotImplementedException; +use Tmdb\HttpClient\HttpClient; use Tmdb\Model\Genre; use Tmdb\Model\Credits as Credits; use Tmdb\Model\Person; @@ -38,11 +39,18 @@ class CreditsFactory extends AbstractFactory */ private $peopleFactory; - public function __construct() + /** + * Constructor + * + * @param HttpClient $httpClient + */ + public function __construct(HttpClient $httpClient) { - $this->tvSeasonFactory = new TvSeasonFactory(); - $this->tvEpisodeFactory = new TvEpisodeFactory(); - $this->peopleFactory = new PeopleFactory(); + $this->tvSeasonFactory = new TvSeasonFactory($httpClient); + $this->tvEpisodeFactory = new TvEpisodeFactory($httpClient); + $this->peopleFactory = new PeopleFactory($httpClient); + + parent::__construct($httpClient); } /** diff --git a/lib/Tmdb/Factory/FindFactory.php b/lib/Tmdb/Factory/FindFactory.php index 34b61ef1..ccc944d3 100644 --- a/lib/Tmdb/Factory/FindFactory.php +++ b/lib/Tmdb/Factory/FindFactory.php @@ -12,6 +12,7 @@ */ namespace Tmdb\Factory; +use Tmdb\HttpClient\HttpClient; use Tmdb\Model\Find; /** @@ -37,12 +38,16 @@ class FindFactory extends AbstractFactory /** * Constructor + * + * @param HttpClient $httpClient */ - public function __construct() + public function __construct(HttpClient $httpClient) { - $this->movieFactory = new MovieFactory(); - $this->peopleFactory = new PeopleFactory(); - $this->tvFactory = new TvFactory(); + $this->movieFactory = new MovieFactory($httpClient); + $this->peopleFactory = new PeopleFactory($httpClient); + $this->tvFactory = new TvFactory($httpClient); + + parent::__construct($httpClient); } /** diff --git a/lib/Tmdb/Factory/ImageFactory.php b/lib/Tmdb/Factory/ImageFactory.php index 9cb6bb4d..84657daf 100644 --- a/lib/Tmdb/Factory/ImageFactory.php +++ b/lib/Tmdb/Factory/ImageFactory.php @@ -74,16 +74,16 @@ public function createMediaImage(array $data = []) if (array_key_exists('media', $data) && array_key_exists('media_type', $data)) { switch ($data['media_type']) { case "movie": - $factory = new MovieFactory(); + $factory = new MovieFactory($this->getHttpClient()); break; case "tv": - $factory = new TvFactory(); + $factory = new TvFactory($this->getHttpClient()); break; // I don't think this ever occurs, but just in case.. case "person": - $factory = new PeopleFactory(); + $factory = new PeopleFactory($this->getHttpClient()); break; default: diff --git a/lib/Tmdb/Factory/ListFactory.php b/lib/Tmdb/Factory/ListFactory.php index a1e73497..e008acbb 100644 --- a/lib/Tmdb/Factory/ListFactory.php +++ b/lib/Tmdb/Factory/ListFactory.php @@ -13,6 +13,7 @@ namespace Tmdb\Factory; use Tmdb\Factory\Lists\ListItemFactory; +use Tmdb\HttpClient\HttpClient; use Tmdb\Model\Common\GenericCollection; use Tmdb\Model\Genre; use Tmdb\Model\Lists; @@ -33,10 +34,17 @@ class ListFactory extends AbstractFactory */ private $listItemFactory; - public function __construct() + /** + * Constructor + * + * @param HttpClient $httpClient + */ + public function __construct(HttpClient $httpClient) { - $this->imageFactory = new ImageFactory(); - $this->listItemFactory = new ListItemFactory(); + $this->imageFactory = new ImageFactory($httpClient); + $this->listItemFactory = new ListItemFactory($httpClient); + + parent::__construct($httpClient); } /** diff --git a/lib/Tmdb/Factory/Lists/ListItemFactory.php b/lib/Tmdb/Factory/Lists/ListItemFactory.php index 34fe946d..b4c24c10 100644 --- a/lib/Tmdb/Factory/Lists/ListItemFactory.php +++ b/lib/Tmdb/Factory/Lists/ListItemFactory.php @@ -14,6 +14,7 @@ use Tmdb\Factory\AbstractFactory; use Tmdb\Factory\ImageFactory; +use Tmdb\HttpClient\HttpClient; use Tmdb\Model\Common\GenericCollection; use Tmdb\Model\Lists\ListItem; @@ -28,9 +29,16 @@ class ListItemFactory extends AbstractFactory */ private $imageFactory; - public function __construct() + /** + * Constructor + * + * @param HttpClient $httpClient + */ + public function __construct(HttpClient $httpClient) { - $this->imageFactory = new ImageFactory(); + $this->imageFactory = new ImageFactory($httpClient); + + parent::__construct($httpClient); } /** diff --git a/lib/Tmdb/Factory/Movie/ListItemFactory.php b/lib/Tmdb/Factory/Movie/ListItemFactory.php index 6e1d5769..1d4a48b1 100644 --- a/lib/Tmdb/Factory/Movie/ListItemFactory.php +++ b/lib/Tmdb/Factory/Movie/ListItemFactory.php @@ -14,6 +14,7 @@ use Tmdb\Factory\AbstractFactory; use Tmdb\Factory\ImageFactory; +use Tmdb\HttpClient\HttpClient; use Tmdb\Model\Movie\ListItem; /** @@ -22,11 +23,21 @@ */ class ListItemFactory extends AbstractFactory { + /** + * @var ImageFactory + */ private $imageFactory; - public function __construct() + /** + * Constructor + * + * @param HttpClient $httpClient + */ + public function __construct(HttpClient $httpClient) { - $this->imageFactory = new ImageFactory(); + $this->imageFactory = new ImageFactory($httpClient); + + parent::__construct($httpClient); } /** diff --git a/lib/Tmdb/Factory/MovieFactory.php b/lib/Tmdb/Factory/MovieFactory.php index 7240cc7e..b6427eb6 100644 --- a/lib/Tmdb/Factory/MovieFactory.php +++ b/lib/Tmdb/Factory/MovieFactory.php @@ -17,6 +17,7 @@ use Tmdb\Factory\Movie\ListItemFactory; use Tmdb\Factory\People\CastFactory; use Tmdb\Factory\People\CrewFactory; +use Tmdb\HttpClient\HttpClient; use Tmdb\Model\Common\Country; use Tmdb\Model\Common\GenericCollection; use Tmdb\Model\Common\SpokenLanguage; @@ -77,18 +78,22 @@ class MovieFactory extends AbstractFactory /** * Constructor + * + * @param HttpClient $httpClient */ - public function __construct() + public function __construct(HttpClient $httpClient) { - $this->castFactory = new CastFactory(); - $this->crewFactory = new CrewFactory(); - $this->genreFactory = new GenreFactory(); - $this->imageFactory = new ImageFactory(); - $this->changeFactory = new ChangeFactory(); - $this->reviewFactory = new ReviewFactory(); - $this->listItemFactory = new ListItemFactory(); - $this->keywordFactory = new KeywordFactory(); - $this->videoFactory = new VideoFactory(); + $this->castFactory = new CastFactory($httpClient); + $this->crewFactory = new CrewFactory($httpClient); + $this->genreFactory = new GenreFactory($httpClient); + $this->imageFactory = new ImageFactory($httpClient); + $this->changeFactory = new ChangeFactory($httpClient); + $this->reviewFactory = new ReviewFactory($httpClient); + $this->listItemFactory = new ListItemFactory($httpClient); + $this->keywordFactory = new KeywordFactory($httpClient); + $this->videoFactory = new VideoFactory($httpClient); + + parent::__construct($httpClient); } /** diff --git a/lib/Tmdb/Factory/People/CastFactory.php b/lib/Tmdb/Factory/People/CastFactory.php index 466b5ac1..5efcadbf 100644 --- a/lib/Tmdb/Factory/People/CastFactory.php +++ b/lib/Tmdb/Factory/People/CastFactory.php @@ -13,6 +13,7 @@ namespace Tmdb\Factory\People; use Tmdb\Factory\PeopleFactory; +use Tmdb\HttpClient\HttpClient; use Tmdb\Model\Collection\People\Cast; /** @@ -21,6 +22,16 @@ */ class CastFactory extends PeopleFactory { + /** + * Constructor + * + * @param HttpClient $httpClient + */ + public function __construct(HttpClient $httpClient) + { + parent::__construct($httpClient); + } + /** * {@inheritdoc} */ diff --git a/lib/Tmdb/Factory/People/CrewFactory.php b/lib/Tmdb/Factory/People/CrewFactory.php index 275cac66..b959e061 100644 --- a/lib/Tmdb/Factory/People/CrewFactory.php +++ b/lib/Tmdb/Factory/People/CrewFactory.php @@ -13,6 +13,7 @@ namespace Tmdb\Factory\People; use Tmdb\Factory\PeopleFactory; +use Tmdb\HttpClient\HttpClient; use Tmdb\Model\Collection\People\Crew; /** @@ -21,6 +22,16 @@ */ class CrewFactory extends PeopleFactory { + /** + * Constructor + * + * @param HttpClient $httpClient + */ + public function __construct(HttpClient $httpClient) + { + parent::__construct($httpClient); + } + /** * {@inheritdoc} */ diff --git a/lib/Tmdb/Factory/PeopleFactory.php b/lib/Tmdb/Factory/PeopleFactory.php index 42a72234..b2eb265d 100644 --- a/lib/Tmdb/Factory/PeopleFactory.php +++ b/lib/Tmdb/Factory/PeopleFactory.php @@ -14,6 +14,7 @@ use Tmdb\Common\ObjectHydrator; use Tmdb\Factory\Common\ChangeFactory; +use Tmdb\HttpClient\HttpClient; use Tmdb\Model\Collection\People; use Tmdb\Model\Common\ExternalIds; use Tmdb\Model\Person\CastMember; @@ -34,11 +35,15 @@ class PeopleFactory extends AbstractFactory /** * Constructor + * + * @param HttpClient $httpClient */ - public function __construct() + public function __construct(HttpClient $httpClient) { - $this->imageFactory = new ImageFactory(); - $this->changeFactory = new ChangeFactory(); + $this->imageFactory = new ImageFactory($httpClient); + $this->changeFactory = new ChangeFactory($httpClient); + + parent::__construct($httpClient); } /** diff --git a/lib/Tmdb/Factory/TvEpisodeFactory.php b/lib/Tmdb/Factory/TvEpisodeFactory.php index 8ec46d3f..6b86747e 100644 --- a/lib/Tmdb/Factory/TvEpisodeFactory.php +++ b/lib/Tmdb/Factory/TvEpisodeFactory.php @@ -16,6 +16,7 @@ use Tmdb\Factory\Common\VideoFactory; use Tmdb\Factory\People\CastFactory; use Tmdb\Factory\People\CrewFactory; +use Tmdb\HttpClient\HttpClient; use Tmdb\Model\Common\GenericCollection; use Tmdb\Model\Person\CastMember; use Tmdb\Model\Person\CrewMember; @@ -55,14 +56,18 @@ class TvEpisodeFactory extends AbstractFactory /** * Constructor + * + * @param HttpClient $httpClient */ - public function __construct() + public function __construct(HttpClient $httpClient) { - $this->castFactory = new CastFactory(); - $this->crewFactory = new CrewFactory(); - $this->imageFactory = new ImageFactory(); - $this->videoFactory = new VideoFactory(); - $this->changesFactory = new ChangeFactory(); + $this->castFactory = new CastFactory($httpClient); + $this->crewFactory = new CrewFactory($httpClient); + $this->imageFactory = new ImageFactory($httpClient); + $this->videoFactory = new VideoFactory($httpClient); + $this->changesFactory = new ChangeFactory($httpClient); + + parent::__construct($httpClient); } /** @@ -116,7 +121,7 @@ public function create(array $data = []) } if (array_key_exists('videos', $data)) { - $tvEpisode->setVideos($this->getVideoFactory()->createCollection($data['videos'])); + $tvEpisode->setVideos($this->getVideoFactory()->createResultCollection($data['videos'])); } if (array_key_exists('changes', $data)) { diff --git a/lib/Tmdb/Factory/TvFactory.php b/lib/Tmdb/Factory/TvFactory.php index be65c902..c9b88585 100644 --- a/lib/Tmdb/Factory/TvFactory.php +++ b/lib/Tmdb/Factory/TvFactory.php @@ -16,6 +16,7 @@ use Tmdb\Factory\Common\VideoFactory; use Tmdb\Factory\People\CastFactory; use Tmdb\Factory\People\CrewFactory; +use Tmdb\HttpClient\HttpClient; use Tmdb\Model\Common\Country; use Tmdb\Model\Common\GenericCollection; use Tmdb\Model\Common\SpokenLanguage; @@ -78,18 +79,22 @@ class TvFactory extends AbstractFactory /** * Constructor + * + * @param HttpClient $httpClient */ - public function __construct() + public function __construct(HttpClient $httpClient) { - $this->castFactory = new CastFactory(); - $this->crewFactory = new CrewFactory(); - $this->genreFactory = new GenreFactory(); - $this->imageFactory = new ImageFactory(); - $this->tvSeasonFactory = new TvSeasonFactory(); - $this->networkFactory = new NetworkFactory(); - $this->videoFactory = new VideoFactory(); - $this->changesFactory = new ChangeFactory(); - $this->keywordFactory = new KeywordFactory(); + $this->castFactory = new CastFactory($httpClient); + $this->crewFactory = new CrewFactory($httpClient); + $this->genreFactory = new GenreFactory($httpClient); + $this->imageFactory = new ImageFactory($httpClient); + $this->tvSeasonFactory = new TvSeasonFactory($httpClient); + $this->networkFactory = new NetworkFactory($httpClient); + $this->videoFactory = new VideoFactory($httpClient); + $this->changesFactory = new ChangeFactory($httpClient); + $this->keywordFactory = new KeywordFactory($httpClient); + + parent::__construct($httpClient); } /** @@ -224,7 +229,7 @@ public function create(array $data = []) if (array_key_exists('created_by', $data) && $data['created_by'] !== null) { $collection = new GenericCollection(); - $factory = new PeopleFactory(); + $factory = new PeopleFactory($this->getHttpClient()); foreach ($data['created_by'] as $castMember) { $object = $factory->create($castMember, new CastMember()); diff --git a/lib/Tmdb/Factory/TvSeasonFactory.php b/lib/Tmdb/Factory/TvSeasonFactory.php index d876a8f0..d2f97777 100644 --- a/lib/Tmdb/Factory/TvSeasonFactory.php +++ b/lib/Tmdb/Factory/TvSeasonFactory.php @@ -16,6 +16,7 @@ use Tmdb\Factory\Common\VideoFactory; use Tmdb\Factory\People\CastFactory; use Tmdb\Factory\People\CrewFactory; +use Tmdb\HttpClient\HttpClient; use Tmdb\Model\Common\GenericCollection; use Tmdb\Model\Person\CastMember; use Tmdb\Model\Person\CrewMember; @@ -60,16 +61,19 @@ class TvSeasonFactory extends AbstractFactory /** * Constructor + * + * @param HttpClient $httpClient */ - public function __construct() + public function __construct(HttpClient $httpClient) { - $this->castFactory = new CastFactory(); - $this->crewFactory = new CrewFactory(); - $this->imageFactory = new ImageFactory(); - $this->tvEpisodeFactory = new TvEpisodeFactory(); - $this->videoFactory = new VideoFactory(); - $this->changesFactory = new ChangeFactory(); - + $this->castFactory = new CastFactory($httpClient); + $this->crewFactory = new CrewFactory($httpClient); + $this->imageFactory = new ImageFactory($httpClient); + $this->tvEpisodeFactory = new TvEpisodeFactory($httpClient); + $this->videoFactory = new VideoFactory($httpClient); + $this->changesFactory = new ChangeFactory($httpClient); + + parent::__construct($httpClient); } /** diff --git a/lib/Tmdb/HttpClient/HttpClient.php b/lib/Tmdb/HttpClient/HttpClient.php index f07c912c..3318898c 100644 --- a/lib/Tmdb/HttpClient/HttpClient.php +++ b/lib/Tmdb/HttpClient/HttpClient.php @@ -21,6 +21,7 @@ use Symfony\Component\EventDispatcher\EventDispatcher; use Tmdb\ApiToken; use Tmdb\Common\ParameterBag; +use Tmdb\Event\HydrationSubscriber; use Tmdb\Event\RequestEvent; use Tmdb\Event\RequestSubscriber; use Tmdb\Event\TmdbEvents; @@ -293,12 +294,8 @@ public function getSessionToken() */ public function setSessionToken(SessionToken $sessionToken) { - // for some reason the TMDB API is inconsistent with it's usage of the session_id query parameter - // guest session id's are used in the URL itself, while regular sessions use the session_id query parameter - if (!($sessionToken instanceof GuestSessionToken)) { - $sessionTokenPlugin = new SessionTokenPlugin($sessionToken); - $this->addSubscriber($sessionTokenPlugin); - } + $sessionTokenPlugin = new SessionTokenPlugin($sessionToken); + $this->addSubscriber($sessionTokenPlugin); $this->sessionToken = $sessionToken; } @@ -337,6 +334,9 @@ public function registerDefaults() $requestSubscriber = new RequestSubscriber(); $this->addSubscriber($requestSubscriber); + $hydrationSubscriber = new HydrationSubscriber(); + $this->addSubscriber($hydrationSubscriber); + $apiTokenPlugin = new ApiTokenPlugin( is_string($this->options['token']) ? new ApiToken($this->options['token']): diff --git a/lib/Tmdb/Repository/AbstractRepository.php b/lib/Tmdb/Repository/AbstractRepository.php index 22ac7f8f..de66bce1 100644 --- a/lib/Tmdb/Repository/AbstractRepository.php +++ b/lib/Tmdb/Repository/AbstractRepository.php @@ -12,6 +12,7 @@ */ namespace Tmdb\Repository; +use Symfony\Component\EventDispatcher\EventDispatcher; use Tmdb\Api\ApiInterface; use Tmdb\Client; use Tmdb\Factory\AbstractFactory; @@ -23,8 +24,8 @@ */ abstract class AbstractRepository { - protected $client = null; - protected $api = null; + protected $client = null; + protected $api = null; /** * Constructor @@ -33,7 +34,7 @@ abstract class AbstractRepository */ public function __construct(Client $client) { - $this->client = $client; + $this->client = $client; } /** @@ -46,6 +47,14 @@ public function getClient() return $this->client; } + /** + * @return EventDispatcher + */ + public function getEventDispatcher() + { + return $this->client->getEventDispatcher(); + } + /** * Process query parameters * diff --git a/lib/Tmdb/Repository/AccountRepository.php b/lib/Tmdb/Repository/AccountRepository.php index 1d1854ed..878e849f 100644 --- a/lib/Tmdb/Repository/AccountRepository.php +++ b/lib/Tmdb/Repository/AccountRepository.php @@ -209,6 +209,6 @@ public function getApi() */ public function getFactory() { - return new AccountFactory(); + return new AccountFactory($this->getClient()->getHttpClient()); } } diff --git a/lib/Tmdb/Repository/AuthenticationRepository.php b/lib/Tmdb/Repository/AuthenticationRepository.php index b2c23ff4..e433caf8 100644 --- a/lib/Tmdb/Repository/AuthenticationRepository.php +++ b/lib/Tmdb/Repository/AuthenticationRepository.php @@ -145,6 +145,6 @@ public function getApi() */ public function getFactory() { - return new AuthenticationFactory(); + return new AuthenticationFactory($this->getClient()->getHttpClient()); } } diff --git a/lib/Tmdb/Repository/CertificationRepository.php b/lib/Tmdb/Repository/CertificationRepository.php index e881690e..c536b9d4 100644 --- a/lib/Tmdb/Repository/CertificationRepository.php +++ b/lib/Tmdb/Repository/CertificationRepository.php @@ -53,6 +53,6 @@ public function getApi() */ public function getFactory() { - return new CertificationFactory(); + return new CertificationFactory($this->getClient()->getHttpClient()); } } diff --git a/lib/Tmdb/Repository/ChangesRepository.php b/lib/Tmdb/Repository/ChangesRepository.php index a8f89605..484a520b 100644 --- a/lib/Tmdb/Repository/ChangesRepository.php +++ b/lib/Tmdb/Repository/ChangesRepository.php @@ -104,6 +104,6 @@ public function getApi() */ public function getFactory() { - return new ChangesFactory(); + return new ChangesFactory($this->getClient()->getHttpClient()); } } diff --git a/lib/Tmdb/Repository/CollectionRepository.php b/lib/Tmdb/Repository/CollectionRepository.php index 9765c006..a0d4afe8 100644 --- a/lib/Tmdb/Repository/CollectionRepository.php +++ b/lib/Tmdb/Repository/CollectionRepository.php @@ -31,7 +31,7 @@ public function __construct(Client $client) { parent::__construct($client); - $this->imageFactory = new ImageFactory(); + $this->imageFactory = new ImageFactory($this->getClient()->getHttpClient()); } /** @@ -91,7 +91,7 @@ public function getApi() */ public function getFactory() { - return new CollectionFactory(); + return new CollectionFactory($this->getClient()->getHttpClient()); } /** diff --git a/lib/Tmdb/Repository/CompanyRepository.php b/lib/Tmdb/Repository/CompanyRepository.php index a87e7d9a..3cb4bbad 100644 --- a/lib/Tmdb/Repository/CompanyRepository.php +++ b/lib/Tmdb/Repository/CompanyRepository.php @@ -69,7 +69,7 @@ public function getApi() */ public function getFactory() { - return new CompanyFactory(); + return new MovieFactory($this->getClient()->getHttpClient()); } /** @@ -77,7 +77,7 @@ public function getFactory() */ public function getMovieFactory() { - return new MovieFactory(); + return new MovieFactory($this->getClient()->getHttpClient()); } /** diff --git a/lib/Tmdb/Repository/ConfigurationRepository.php b/lib/Tmdb/Repository/ConfigurationRepository.php index 6dcb43c8..e00242a0 100644 --- a/lib/Tmdb/Repository/ConfigurationRepository.php +++ b/lib/Tmdb/Repository/ConfigurationRepository.php @@ -50,6 +50,6 @@ public function getApi() */ public function getFactory() { - return new ConfigurationFactory(); + return new ConfigurationFactory($this->getClient()->getHttpClient()); } } diff --git a/lib/Tmdb/Repository/CreditsRepository.php b/lib/Tmdb/Repository/CreditsRepository.php index c2fc13fa..79ef9e31 100644 --- a/lib/Tmdb/Repository/CreditsRepository.php +++ b/lib/Tmdb/Repository/CreditsRepository.php @@ -51,6 +51,6 @@ public function getApi() */ public function getFactory() { - return new CreditsFactory(); + return new CreditsFactory($this->getClient()->getHttpClient()); } } diff --git a/lib/Tmdb/Repository/DiscoverRepository.php b/lib/Tmdb/Repository/DiscoverRepository.php index 7dcf3149..9d29bb5a 100644 --- a/lib/Tmdb/Repository/DiscoverRepository.php +++ b/lib/Tmdb/Repository/DiscoverRepository.php @@ -91,7 +91,7 @@ public function getFactory() */ public function getMovieFactory() { - return new MovieFactory(); + return new MovieFactory($this->getClient()->getHttpClient()); } /** @@ -99,6 +99,6 @@ public function getMovieFactory() */ public function getTvFactory() { - return new TvFactory(); + return new TvFactory($this->getClient()->getHttpClient()); } } diff --git a/lib/Tmdb/Repository/FindRepository.php b/lib/Tmdb/Repository/FindRepository.php index a07ddebf..9e771cc3 100644 --- a/lib/Tmdb/Repository/FindRepository.php +++ b/lib/Tmdb/Repository/FindRepository.php @@ -52,6 +52,6 @@ public function getApi() */ public function getFactory() { - return new FindFactory(); + return new FindFactory($this->getClient()->getHttpClient()); } } diff --git a/lib/Tmdb/Repository/GenreRepository.php b/lib/Tmdb/Repository/GenreRepository.php index 7be9f3e5..728acb39 100644 --- a/lib/Tmdb/Repository/GenreRepository.php +++ b/lib/Tmdb/Repository/GenreRepository.php @@ -93,6 +93,6 @@ public function getApi() */ public function getFactory() { - return new GenreFactory(); + return new GenreFactory($this->getClient()->getHttpClient()); } } diff --git a/lib/Tmdb/Repository/GuestSessionRepository.php b/lib/Tmdb/Repository/GuestSessionRepository.php index dc1025ba..459caa15 100644 --- a/lib/Tmdb/Repository/GuestSessionRepository.php +++ b/lib/Tmdb/Repository/GuestSessionRepository.php @@ -57,7 +57,7 @@ public function getApi() */ public function getFactory() { - return new GuestSessionFactory(); + return new GuestSessionFactory($this->getClient()->getHttpClient()); } /** @@ -65,6 +65,6 @@ public function getFactory() */ public function getMovieFactory() { - return new MovieFactory(); + return new MovieFactory($this->getClient()->getHttpClient()); } } diff --git a/lib/Tmdb/Repository/JobsRepository.php b/lib/Tmdb/Repository/JobsRepository.php index 18e37a5a..6e6f54d5 100644 --- a/lib/Tmdb/Repository/JobsRepository.php +++ b/lib/Tmdb/Repository/JobsRepository.php @@ -73,6 +73,6 @@ public function getApi() */ public function getFactory() { - return new JobsFactory(); + return new JobsFactory($this->getClient()->getHttpClient()); } } diff --git a/lib/Tmdb/Repository/KeywordRepository.php b/lib/Tmdb/Repository/KeywordRepository.php index 1b3398c6..9b0f2131 100644 --- a/lib/Tmdb/Repository/KeywordRepository.php +++ b/lib/Tmdb/Repository/KeywordRepository.php @@ -70,6 +70,6 @@ public function getApi() */ public function getFactory() { - return new KeywordFactory(); + return new KeywordFactory($this->getClient()->getHttpClient()); } } diff --git a/lib/Tmdb/Repository/ListRepository.php b/lib/Tmdb/Repository/ListRepository.php index a2299ef1..7d058fc6 100644 --- a/lib/Tmdb/Repository/ListRepository.php +++ b/lib/Tmdb/Repository/ListRepository.php @@ -146,6 +146,6 @@ public function getApi() */ public function getFactory() { - return new ListFactory(); + return new ListFactory($this->getClient()->getHttpClient()); } } diff --git a/lib/Tmdb/Repository/MovieRepository.php b/lib/Tmdb/Repository/MovieRepository.php index 7e10be15..cbff50a2 100644 --- a/lib/Tmdb/Repository/MovieRepository.php +++ b/lib/Tmdb/Repository/MovieRepository.php @@ -394,7 +394,7 @@ public function getApi() */ public function getFactory() { - return new MovieFactory(); + return new MovieFactory($this->getClient()->getHttpClient()); } /** diff --git a/lib/Tmdb/Repository/NetworkRepository.php b/lib/Tmdb/Repository/NetworkRepository.php index cd5e5c96..0e843a95 100644 --- a/lib/Tmdb/Repository/NetworkRepository.php +++ b/lib/Tmdb/Repository/NetworkRepository.php @@ -55,6 +55,6 @@ public function getApi() */ public function getFactory() { - return new NetworkFactory(); + return new NetworkFactory($this->getClient()->getHttpClient()); } } diff --git a/lib/Tmdb/Repository/PeopleRepository.php b/lib/Tmdb/Repository/PeopleRepository.php index 6fb26782..db9555d0 100644 --- a/lib/Tmdb/Repository/PeopleRepository.php +++ b/lib/Tmdb/Repository/PeopleRepository.php @@ -182,7 +182,7 @@ public function getTaggedImages($id, array $parameters = [], array $headers = [] { $data = $this->getApi()->getTaggedImages($id, $this->parseQueryParameters($parameters), $headers); - $factory = new ImageFactory(); + $factory = new ImageFactory($this->getClient()->getHttpClient()); return $factory->createResultCollection($data, 'createMediaImage'); } @@ -230,6 +230,6 @@ public function getApi() */ public function getFactory() { - return new PeopleFactory(); + return new PeopleFactory($this->getClient()->getHttpClient()); } } diff --git a/lib/Tmdb/Repository/ReviewRepository.php b/lib/Tmdb/Repository/ReviewRepository.php index 592902cb..0d519092 100644 --- a/lib/Tmdb/Repository/ReviewRepository.php +++ b/lib/Tmdb/Repository/ReviewRepository.php @@ -52,6 +52,6 @@ public function getApi() */ public function getFactory() { - return new ReviewFactory(); + return new ReviewFactory($this->getClient()->getHttpClient()); } } diff --git a/lib/Tmdb/Repository/SearchRepository.php b/lib/Tmdb/Repository/SearchRepository.php index 92500475..0451947c 100644 --- a/lib/Tmdb/Repository/SearchRepository.php +++ b/lib/Tmdb/Repository/SearchRepository.php @@ -82,13 +82,13 @@ public function __construct(Client $client) { parent::__construct($client); - $this->movieFactory = new MovieFactory(); - $this->collectionFactory = new CollectionFactory(); - $this->tvFactory = new TvFactory(); - $this->peopleFactory = new PeopleFactory(); - $this->listItemFactory = new ListItemFactory(); - $this->companyFactory = new CompanyFactory(); - $this->keywordFactory = new KeywordFactory(); + $this->movieFactory = new MovieFactory($this->getClient()->getHttpClient()); + $this->collectionFactory = new CollectionFactory($this->getClient()->getHttpClient()); + $this->tvFactory = new TvFactory($this->getClient()->getHttpClient()); + $this->peopleFactory = new PeopleFactory($this->getClient()->getHttpClient()); + $this->listItemFactory = new ListItemFactory($this->getClient()->getHttpClient()); + $this->companyFactory = new CompanyFactory($this->getClient()->getHttpClient()); + $this->keywordFactory = new KeywordFactory($this->getClient()->getHttpClient()); } /** diff --git a/lib/Tmdb/Repository/TimezoneRepository.php b/lib/Tmdb/Repository/TimezoneRepository.php index 7f9fe148..dce53b4a 100644 --- a/lib/Tmdb/Repository/TimezoneRepository.php +++ b/lib/Tmdb/Repository/TimezoneRepository.php @@ -51,6 +51,6 @@ public function getApi() */ public function getFactory() { - return new TimezoneFactory(); + return new TimezoneFactory($this->getClient()->getHttpClient()); } } diff --git a/lib/Tmdb/Repository/TvEpisodeRepository.php b/lib/Tmdb/Repository/TvEpisodeRepository.php index 1553e8bf..248fa862 100644 --- a/lib/Tmdb/Repository/TvEpisodeRepository.php +++ b/lib/Tmdb/Repository/TvEpisodeRepository.php @@ -68,7 +68,8 @@ public function load($tvShow, $season, $episode, array $parameters = [], array $ AppendToResponse::CREDITS, AppendToResponse::EXTERNAL_IDS, AppendToResponse::IMAGES, - AppendToResponse::CHANGES + AppendToResponse::CHANGES, + AppendToResponse::VIDEOS ]) ]; } @@ -309,6 +310,6 @@ public function getApi() */ public function getFactory() { - return new TvEpisodeFactory(); + return new TvEpisodeFactory($this->getClient()->getHttpClient()); } } diff --git a/lib/Tmdb/Repository/TvRepository.php b/lib/Tmdb/Repository/TvRepository.php index 3e15a920..0c2f8c7e 100644 --- a/lib/Tmdb/Repository/TvRepository.php +++ b/lib/Tmdb/Repository/TvRepository.php @@ -159,7 +159,7 @@ public function getApi() */ public function getFactory() { - return new TvFactory(); + return new TvFactory($this->getClient()->getHttpClient()); } /** diff --git a/lib/Tmdb/Repository/TvSeasonRepository.php b/lib/Tmdb/Repository/TvSeasonRepository.php index 2506b18a..8ad6a470 100644 --- a/lib/Tmdb/Repository/TvSeasonRepository.php +++ b/lib/Tmdb/Repository/TvSeasonRepository.php @@ -59,7 +59,8 @@ public function load($tvShow, $season, array $parameters = [], array $headers = AppendToResponse::CREDITS, AppendToResponse::EXTERNAL_IDS, AppendToResponse::IMAGES, - AppendToResponse::CHANGES + AppendToResponse::CHANGES, + AppendToResponse::VIDEOS ]) ]; } @@ -186,6 +187,6 @@ public function getApi() */ public function getFactory() { - return new TvSeasonFactory(); + return new TvSeasonFactory($this->getClient()->getHttpClient()); } } diff --git a/test/Tmdb/Tests/Api/GuestSessionTest.php b/test/Tmdb/Tests/Api/GuestSessionTest.php index 21a8b686..ca46aa9f 100644 --- a/test/Tmdb/Tests/Api/GuestSessionTest.php +++ b/test/Tmdb/Tests/Api/GuestSessionTest.php @@ -35,7 +35,10 @@ public function shouldGetRatedMovies() $sessionToken = new GuestSessionToken('xyz'); $api = $this->getApiWithMockedHttpAdapter(['session_token' => $sessionToken]); - $request = $this->getRequest(sprintf('guest_session/%s/rated_movies', (string) $sessionToken)); + $request = $this->getRequest( + sprintf('guest_session/%s/rated_movies', (string) $sessionToken), + ['guest_session_id' => (string) $sessionToken] + ); $request->getOptions()->set('session_token', $sessionToken); $this->getAdapter()->expects($this->once()) diff --git a/test/Tmdb/Tests/Factory/PeopleFactoryTest.php b/test/Tmdb/Tests/Factory/PeopleFactoryTest.php index 76db8d24..340c75cc 100644 --- a/test/Tmdb/Tests/Factory/PeopleFactoryTest.php +++ b/test/Tmdb/Tests/Factory/PeopleFactoryTest.php @@ -60,7 +60,7 @@ public function shouldConstructCastAndCredits() /** * @var MovieFactory $movieFactory */ - $movieFactory = new MovieFactory(); + $movieFactory = new MovieFactory($this->getHttpClient()); /** * @var Movie $movie diff --git a/test/Tmdb/Tests/Factory/TestCase.php b/test/Tmdb/Tests/Factory/TestCase.php index 24cdb61a..7a139972 100644 --- a/test/Tmdb/Tests/Factory/TestCase.php +++ b/test/Tmdb/Tests/Factory/TestCase.php @@ -12,17 +12,34 @@ */ namespace Tmdb\Tests\Factory; +use Tmdb\ApiToken; +use Tmdb\Client; use Tmdb\Tests\TestCase as Base; abstract class TestCase extends Base { + /** + * @var Client + */ + private $client; + + public function __construct() + { + $this->client = new Client(new ApiToken('abcdef')); + } + protected $factory; protected function getFactory() { $class = $this->getFactoryClass(); - return new $class(); + return new $class($this->client->getHttpClient()); + } + + protected function getHttpClient() + { + return $this->client->getHttpClient(); } abstract protected function getFactoryClass(); diff --git a/test/Tmdb/Tests/Factory/TvFactoryTest.php b/test/Tmdb/Tests/Factory/TvFactoryTest.php index 0fef8798..e344b8c3 100644 --- a/test/Tmdb/Tests/Factory/TvFactoryTest.php +++ b/test/Tmdb/Tests/Factory/TvFactoryTest.php @@ -60,7 +60,7 @@ public function shouldBeAbleToSetFactories() { $this->setUp(); - $factory = new TvFactory(); + $factory = new TvFactory($this->getHttpClient()); $class = new \stdClass(); $factory->setCastFactory($class); diff --git a/test/Tmdb/Tests/Helper/ImageHelperTest.php b/test/Tmdb/Tests/Helper/ImageHelperTest.php index eb123ca8..0c785463 100644 --- a/test/Tmdb/Tests/Helper/ImageHelperTest.php +++ b/test/Tmdb/Tests/Helper/ImageHelperTest.php @@ -12,6 +12,8 @@ */ namespace Tmdb\Tests\Helper; +use Tmdb\ApiToken; +use Tmdb\Client; use Tmdb\Tests\TestCase as Base; class ImageHelperTest extends Base @@ -23,7 +25,9 @@ class ImageHelperTest extends Base public function setUp() { - $factory = new \Tmdb\Factory\ConfigurationFactory(); + $client = new Client(new ApiToken('abcdef')); + + $factory = new \Tmdb\Factory\ConfigurationFactory($client->getHttpClient()); $data = $this->loadByFile('configuration/get.json'); $configuration = $factory->create($data); diff --git a/test/Tmdb/Tests/Model/ImageTest.php b/test/Tmdb/Tests/Model/ImageTest.php index 0d135a7f..05a5b46c 100644 --- a/test/Tmdb/Tests/Model/ImageTest.php +++ b/test/Tmdb/Tests/Model/ImageTest.php @@ -12,6 +12,8 @@ */ namespace Tmdb\Tests\Model; +use Tmdb\ApiToken; +use Tmdb\Client; use Tmdb\Factory\ImageFactory; use Tmdb\Model\Collection\Images; use Tmdb\Model\Image; @@ -37,10 +39,12 @@ class ImageTest extends TestCase public function setUp() { + $client = new Client(new ApiToken('abcdef')); $this->collection = new Images(); foreach ($this->images as $image) { - $factory = new ImageFactory(); + + $factory = new ImageFactory($client->getHttpClient()); $object = $factory->create($image); $this->collection->addImage($object); diff --git a/test/Tmdb/Tests/Repository/GuestSessionRepositoryTest.php b/test/Tmdb/Tests/Repository/GuestSessionRepositoryTest.php index cc27d3d2..a1740115 100644 --- a/test/Tmdb/Tests/Repository/GuestSessionRepositoryTest.php +++ b/test/Tmdb/Tests/Repository/GuestSessionRepositoryTest.php @@ -24,7 +24,10 @@ public function shouldGetRatedMovies() $sessionToken = new GuestSessionToken('xyz'); $repository = $this->getRepositoryWithMockedHttpAdapter(['session_token' => $sessionToken]); - $request = $this->getRequest(sprintf('guest_session/%s/rated_movies', (string) $sessionToken)); + $request = $this->getRequest( + sprintf('guest_session/%s/rated_movies', (string) $sessionToken), + ['guest_session_id' => (string) $sessionToken] + ); $request->getOptions()->set('session_token', $sessionToken); $this->getAdapter()->expects($this->once()) diff --git a/test/Tmdb/Tests/Repository/TvEpisodeRepositoryTest.php b/test/Tmdb/Tests/Repository/TvEpisodeRepositoryTest.php index 789ba4e9..22097065 100644 --- a/test/Tmdb/Tests/Repository/TvEpisodeRepositoryTest.php +++ b/test/Tmdb/Tests/Repository/TvEpisodeRepositoryTest.php @@ -33,7 +33,7 @@ public function shouldLoadTvEpisode() ->method('get') ->with($this->getRequest( 'tv/' . self::TV_ID . '/season/' . self::SEASON_ID . '/episode/' . self::EPISODE_ID, - ['append_to_response' => 'credits,external_ids,images,changes'] + ['append_to_response' => 'credits,external_ids,images,changes,videos'] )) ; @@ -51,7 +51,7 @@ public function shouldBeAbleToLoadTvSeasonWithTvAndSeason() ->method('get') ->with($this->getRequest( 'tv/' . self::TV_ID . '/season/' . self::SEASON_ID . '/episode/' . self::EPISODE_ID, - ['append_to_response' => 'credits,external_ids,images,changes'] + ['append_to_response' => 'credits,external_ids,images,changes,videos'] )) ; diff --git a/test/Tmdb/Tests/Repository/TvSeasonRepositoryTest.php b/test/Tmdb/Tests/Repository/TvSeasonRepositoryTest.php index 4782ac45..8e97b305 100644 --- a/test/Tmdb/Tests/Repository/TvSeasonRepositoryTest.php +++ b/test/Tmdb/Tests/Repository/TvSeasonRepositoryTest.php @@ -30,7 +30,7 @@ public function shouldLoadTvSeason() ->method('get') ->with($this->getRequest( 'tv/' . self::TV_ID . '/season/' . self::SEASON_ID, - ['append_to_response' => 'credits,external_ids,images,changes'] + ['append_to_response' => 'credits,external_ids,images,changes,videos'] )) ; @@ -48,7 +48,7 @@ public function shouldBeAbleToLoadTvSeasonWithTvAndSeason() ->method('get') ->with($this->getRequest( 'tv/' . self::TV_ID . '/season/' . self::SEASON_ID, - ['append_to_response' => 'credits,external_ids,images,changes'] + ['append_to_response' => 'credits,external_ids,images,changes,videos'] )) ; From 04ff0e106da1127bf409c5e4e477d8d3e91b1e9c Mon Sep 17 00:00:00 2001 From: Michael Roterman Date: Sun, 25 Jan 2015 15:45:40 +0100 Subject: [PATCH 2/2] Fix broken examples --- examples/movies/model/rate.php | 2 +- examples/tv/model/tv/latest.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/movies/model/rate.php b/examples/movies/model/rate.php index 76df3862..c64690ce 100644 --- a/examples/movies/model/rate.php +++ b/examples/movies/model/rate.php @@ -14,7 +14,7 @@ require_once '../../../apikey.php'; $token = new \Tmdb\ApiToken(TMDB_API_KEY); -$client = new \Tmdb\Client($token); +$client = new \Tmdb\Client($token, ['session_token' => new \Tmdb\GuestSessionToken(TMDB_GUEST_SESSION_TOKEN), 'log' => ['enabled' => true, 'handler' => new \Monolog\Handler\ChromePHPHandler()]]); /** $sessionToken = new \Tmdb\SessionToken(TMDB_SESSION_TOKEN); diff --git a/examples/tv/model/tv/latest.php b/examples/tv/model/tv/latest.php index 503c50e4..6555a568 100644 --- a/examples/tv/model/tv/latest.php +++ b/examples/tv/model/tv/latest.php @@ -10,8 +10,8 @@ * @copyright (c) 2013, Michael Roterman * @version 0.0.1 */ -require_once '../../../vendor/autoload.php'; -require_once '../../../apikey.php'; +require_once '../../../../vendor/autoload.php'; +require_once '../../../../apikey.php'; $token = new \Tmdb\ApiToken(TMDB_API_KEY); $client = new \Tmdb\Client($token);