public function testGetHydratorForEntityGivenUnkownEntityAndNoDefaultHydratorDefinedShouldReturnFalse()
 {
     $entity = new TestAsset\Entity('foo', 'Foo Bar');
     $metadataMap = new MetadataMap();
     $metadataMap->setHydratorManager(new HydratorPluginManager(new ServiceManager()));
     $hydratorPluginManager = new HydratorPluginManager(new ServiceManager());
     $entityHydratorManager = new EntityHydratorManager($hydratorPluginManager, $metadataMap);
     $hydrator = $entityHydratorManager->getHydratorForEntity($entity);
     $this->assertFalse($hydrator);
 }
Example #2
0
 /**
  * @group 79
  */
 public function testInjectsLinksFromMetadataWhenCreatingCollection()
 {
     $set = new HalPluginTestAsset\Collection([(object) ['id' => 'foo', 'name' => 'foo'], (object) ['id' => 'bar', 'name' => 'bar'], (object) ['id' => 'baz', 'name' => 'baz']]);
     $metadata = new MetadataMap([HalPluginTestAsset\Collection::class => ['is_collection' => true, 'route_name' => 'hostname/contacts', 'entity_route_name' => 'hostname/embedded', 'links' => [['rel' => 'describedby', 'url' => 'http://example.com/api/help/collection']]]]);
     $metadata->setHydratorManager(new HydratorPluginManager(new ServiceManager()));
     $resourceFactory = $this->getResourceFactory($metadata);
     $collection = $resourceFactory->createCollectionFromMetadata($set, $metadata->get(HalPluginTestAsset\Collection::class));
     $this->assertInstanceof('ZF\\Hal\\Collection', $collection);
     $links = $collection->getLinks();
     $this->assertTrue($links->has('describedby'));
     $link = $links->get('describedby');
     $this->assertTrue($link->hasUrl());
     $this->assertEquals('http://example.com/api/help/collection', $link->getUrl());
 }
 /**
  * Retrieve a hydrator for a given entity
  *
  * If the entity has a mapped hydrator, returns that hydrator. If not, and
  * a default hydrator is present, the default hydrator is returned.
  * Otherwise, a boolean false is returned.
  *
  * @param  object $entity
  * @return ExtractionInterface|false
  */
 public function getHydratorForEntity($entity)
 {
     $class = get_class($entity);
     $classLower = strtolower($class);
     if (isset($this->hydratorMap[$classLower])) {
         return $this->hydratorMap[$classLower];
     }
     if ($this->metadataMap->has($entity)) {
         $metadata = $this->metadataMap->get($class);
         $hydrator = $metadata->getHydrator();
         if ($hydrator instanceof ExtractionInterface) {
             $this->addHydrator($class, $hydrator);
             return $hydrator;
         }
     }
     if ($this->defaultHydrator instanceof ExtractionInterface) {
         return $this->defaultHydrator;
     }
     return false;
 }
Example #4
0
 public function testCreateCollectionWithoutForcedSelfLinks()
 {
     $collection = ['foo' => 'bar'];
     $metadata = new MetadataMap(['ZF\\Hal\\Collection' => ['is_collection' => true, 'route_name' => 'hostname/contacts', 'entity_route_name' => 'hostname/embedded', 'links' => [], 'force_self_link' => false]]);
     $metadata->setHydratorManager(new Hydrator\HydratorPluginManager(new ServiceManager()));
     $this->plugin->setMetadataMap($metadata);
     $result = $this->plugin->createCollection($collection);
     $links = $result->getLinks();
     $this->assertFalse($links->has('self'));
 }