コード例 #1
0
ファイル: NetworkTest.php プロジェクト: n10ty/api
 /**
  * @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());
 }
コード例 #2
0
ファイル: CountryTest.php プロジェクト: n10ty/api
 /**
  * @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());
 }
コード例 #3
0
ファイル: CrewMemberTest.php プロジェクト: n10ty/api
 /**
  * @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());
 }
コード例 #4
0
ファイル: SpokenLanguageTest.php プロジェクト: n10ty/api
 /**
  * @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());
 }
コード例 #5
0
ファイル: CastMemberTest.php プロジェクト: n10ty/api
 /**
  * @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());
 }
コード例 #6
0
ファイル: TranslationTest.php プロジェクト: n10ty/api
 /**
  * @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());
 }
コード例 #7
0
ファイル: ReleaseTest.php プロジェクト: n10ty/api
 /**
  * @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());
 }
コード例 #8
0
ファイル: ExternalIdsTest.php プロジェクト: n10ty/api
 /**
  * @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());
 }
コード例 #9
0
 /**
  * @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;
 }
コード例 #10
0
 /**
  * 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);
             }
         }
     }
 }
コード例 #11
0
ファイル: AbstractFactory.php プロジェクト: nioc/ampache
 /**
  * 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);
 }
コード例 #12
0
 /**
  * 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());
 }
コード例 #13
0
ファイル: TestCase.php プロジェクト: n10ty/api
 /**
  * Hydrate object
  *
  * @param $object
  * @param $data
  * @return \Tmdb\Model\AbstractModel
  */
 protected function hydrate($object, $data)
 {
     $objectHydrator = new ObjectHydrator();
     return $objectHydrator->hydrate($object, $data);
 }