/** * Hydrates an entity with datas * * @param EntityInterface $entity * @param \stdClass $datas * * @return EntityInterface */ public function HydrateEntity(EntityInterface $entity, \stdClass $datas) { return EntityHydrator::hydrate($entity, $datas, $this); }
public function testHydrate() { $client = $this->getMock('PhraseanetSDK\\Client', array(), array(), '', false); $em = new EntityManager($client); $feed = new Feed($em); $feed = EntityHydrator::hydrate($feed, $this->getOneFeed(), $em); $this->assertEquals(3, $feed->getId()); $this->assertEquals('hellow world', $feed->getTitle()); $this->assertEquals('good bye', $feed->getIcon()); $this->assertEquals('what\'s up', $feed->getSubTitle()); $this->assertEquals(4, $feed->getTotalEntries()); $this->assertEquals('2011-07-20T18:45:20+02:00', $feed->getCreatedOn()->format(\DateTime::ATOM)); $this->assertEquals('2011-07-20T18:45:20+02:00', $feed->getUpdatedOn()->format(\DateTime::ATOM)); $entry = new FeedEntry($em); $entry = EntityHydrator::hydrate($entry, $this->getOneFeedEntry(), $em); /* @var $entry \PhraseanetSDK\Entity\Entry */ $this->assertEquals('*****@*****.**', $entry->getAuthorEmail()); $this->assertEquals('*****@*****.**', $entry->getAuthorName()); $this->assertEquals('2011-11-04T14:39:47+01:00', $entry->getCreatedOn()->format(\DateTime::ATOM)); $this->assertEquals('2011-11-04T14:39:47+01:00', $entry->getUpdatedOn()->format(\DateTime::ATOM)); $this->assertEquals('My Entry subtitle', $entry->getSubtitle()); $this->assertEquals('My Entry Test', $entry->getTitle()); $items = $entry->getItems(); /* @var $items Doctrine\Common\Collections\ArrayCollection */ $this->assertTrue($items instanceof ArrayCollection); $this->assertEquals(2, $items->count()); foreach ($items as $item) { $this->assertTrue($item instanceof FeedEntryItem); $record = $item->getRecord(); $this->assertTrue($record instanceof Record); $thumbnail = $record->getThumbnail(); $this->assertTrue($thumbnail instanceof Subdef); $permalink = $thumbnail->getPermalink(); $this->assertTrue($permalink instanceof Permalink); } }