/** * @test */ public function shouldBeFunctional() { $data = array('id' => 1, 'name' => 'name'); $hydrator = new ObjectHydrator(); $object = $hydrator->hydrate(new Network(), $data); $this->assertEquals(1, $object->getId()); $this->assertEquals('name', $object->getName()); }
/** * @test */ public function shouldBeFunctional() { $data = array('iso_3166_1' => 'US', 'name' => 'United States of America'); $hydrator = new ObjectHydrator(); $object = $hydrator->hydrate(new Country(), $data); $this->assertEquals('US', $object->getIso31661()); $this->assertEquals('United States of America', $object->getName()); }
/** * @test */ public function shouldBeFunctional() { $data = array('id' => 7477, 'name' => 'John King', 'department' => 'Sound', 'job' => 'Original Music Composer', 'profile_path' => null); $hydrator = new ObjectHydrator(); $object = $hydrator->hydrate(new CrewMember(), $data); $this->assertEquals(7477, $object->getId()); $this->assertEquals('John King', $object->getName()); $this->assertEquals('Sound', $object->getDepartment()); $this->assertEquals('Original Music Composer', $object->getJob()); $this->assertEquals(null, $object->getProfilePath()); }
/** * @test */ public function shouldBeFunctional() { $data = array('iso_639_1' => 'en', 'name' => 'English'); $hydrator = new ObjectHydrator(); $object = $hydrator->hydrate(new SpokenLanguage(), $data); /** * @var SpokenLanguage $object */ //$this->assertEquals('en', $object->getIso6391()); $this->assertEquals('English', $object->getName()); }
/** * @test */ public function shouldBeFunctional() { $data = array('id' => 819, 'name' => 'Edward Norton', 'character' => 'The Narrator', 'order' => 0, 'cast_id' => 4, 'profile_path' => '/588Hrov6wwM9WcU88nJHlw2iufN.jpg'); $hydrator = new ObjectHydrator(); $object = $hydrator->hydrate(new CastMember(), $data); $this->assertEquals(819, $object->getId()); $this->assertEquals('Edward Norton', $object->getName()); $this->assertEquals('The Narrator', $object->getCharacter()); $this->assertEquals(0, $object->getOrder()); $this->assertEquals(4, $object->getCastId()); $this->assertEquals('/588Hrov6wwM9WcU88nJHlw2iufN.jpg', $object->getProfilePath()); }
/** * @test */ public function shouldBeFunctional() { $data = array('iso_639_1' => 'en', 'name' => 'English', 'english_name' => 'English'); $hydrator = new ObjectHydrator(); $object = $hydrator->hydrate(new Translation(), $data); /** * @var Translation $object */ $this->assertEquals('en', $object->getIso6391()); $this->assertEquals('English', $object->getName()); $this->assertEquals('English', $object->getEnglishName()); }
/** * @test */ public function shouldBeFunctional() { $data = array('iso_3166_1' => 'US', 'certification' => 'R', 'release_date' => '1999-10-15'); $hydrator = new ObjectHydrator(); /** * @var Release $object */ $object = $hydrator->hydrate(new Release(), $data); $this->assertEquals('US', $object->getIso31661()); $this->assertEquals('R', $object->getCertification()); $this->assertEquals(new \DateTime('1999-10-15'), $object->getReleaseDate()); }
/** * @test */ public function shouldBeFunctional() { $data = array('imdb_id' => 'tt0903747', 'freebase_id' => '/en/breaking_bad', 'freebase_mid' => '/m/03d34x8', 'id' => 1396, 'tvdb_id' => 81189, 'tvrage_id' => 18164); $hydrator = new ObjectHydrator(); $object = $hydrator->hydrate(new ExternalIds(), $data); $this->assertEquals('tt0903747', $object->getImdbId()); $this->assertEquals('/en/breaking_bad', $object->getFreebaseId()); $this->assertEquals('/m/03d34x8', $object->getFreebaseMid()); $this->assertEquals(1396, $object->getId()); $this->assertEquals(81189, $object->getTvdbId()); $this->assertEquals(18164, $object->getTvrageId()); }
/** * @param array $data * @param $class * @return GenericCollection */ public function createCollection(array $data, $class) { if (is_object($class)) { $class = get_class($class); } $collection = new GenericCollection(); $objectHydrator = new ObjectHydrator(); foreach ($data as $item) { $collection->add(null, $objectHydrator->hydrate(new $class(), $item)); } return $collection; }
/** * Apply credits * * @param array $data * @param Person $person */ protected function applyCredits(array $data, Person $person) { $hydrator = new ObjectHydrator(); $types = ['movie_credits', 'tv_credits', 'combined_credits']; foreach ($types as $type) { if (array_key_exists($type, $data)) { $method = $hydrator->camelize(sprintf('get_%s', $type)); if (array_key_exists('cast', $data[$type])) { $cast = $this->createCustomCollection($data[$type]['cast'], new Person\MovieCredit(), new People\Cast()); foreach ($cast as $member) { $member->setPosterImage($this->getPosterImageForCredit($member->getPosterPath())); } $person->{$method}()->setCast($cast); } if (array_key_exists('crew', $data[$type])) { $crew = $this->createCustomCollection($data[$type]['crew'], new Person\MovieCredit(), new People\Crew()); foreach ($crew as $member) { $member->setPosterImage($this->getPosterImageForCredit($member->getPosterPath())); } $person->{$method}()->setCrew($crew); } } } }
/** * Hydrate the object with data * * @param AbstractModel $object * @param array $data * @return AbstractModel */ protected function hydrate(AbstractModel $object, $data = array()) { $objectHydrator = new ObjectHydrator(); return $objectHydrator->hydrate($object, $data); }
/** * 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()); }
/** * Hydrate object * * @param $object * @param $data * @return \Tmdb\Model\AbstractModel */ protected function hydrate($object, $data) { $objectHydrator = new ObjectHydrator(); return $objectHydrator->hydrate($object, $data); }