/** * @expectedException \Revinate\SearchBundle\Lib\Search\Exception\Driver\PropertyDoesNotExistsInMetadataException */ public function testLoadMetadataForClassAddValuesToMetadata() { $this->reflectionClass->expects($this->once())->method('getProperties')->will($this->returnValue(array())); $this->reader->expects($this->once())->method('getClassAnnotations')->will($this->returnValue(array(0, new TestSearchable(array())))); $this->classMetadata->expects($this->once())->method('getReflectionClass')->will($this->returnValue($this->reflectionClass)); $this->annotationDriver->loadMetadataForClass('Lib\\Tests\\Models\\Blog\\BlogPost', $this->classMetadata); }
/** * Construct an entity object * * @param ClassMetadata $class * @param object $document */ public function hydrateEntity(ClassMetadata $class, $document) { // TODO: add support for different result set types from different clients // perhaps by wrapping documents in a layer of abstraction $data = $document->getData(); $fields = array_merge($document->hasFields() ? $document->getFields() : array(), array('_version' => $document->getVersion())); foreach ($fields as $name => $value) { if (isset($class->parameters[$name])) { $data[$name] = $value; } else { foreach ($class->parameters as $param => $mapping) { if ($mapping->name == $name) { $data[$param] = $value; break; } } } } $data[$class->getIdentifier()] = $document->getId(); if (method_exists($document, 'getScore')) { $data['score'] = $document->getScore(); } $entity = $this->sm->getSerializer()->deserialize($class->className, json_encode($data)); if ($this->evm->hasListeners(Events::postLoad)) { $this->evm->dispatchEvent(Events::postLoad, new Event\LifecycleEventArgs($entity, $this->sm)); } return $entity; }
public function testGetAssociationMappedByTargetField() { $this->assertInternalType('string', $this->classMetadata->getAssociationMappedByTargetField('name')); }
/** * {@inheritdoc} */ public function updateMapping(ClassMetadata $classMetadata) { try { $elasticaIndex = new Index($this->client, $classMetadata->getIndexForRead()); $elasticaType = new Type($elasticaIndex, $classMetadata->type); $elasticaTypeMapping = new Mapping($elasticaType, $this->getMapping($classMetadata->fieldMappings)); $elasticaTypeMapping->setParam('_id', array('path' => $classMetadata->getIdentifier())); if ($classMetadata->parent) { $elasticaTypeMapping->setParam('_parent', array('type' => $classMetadata->parent)); } if ($classMetadata->dynamic) { $elasticaTypeMapping->setParam('dynamic', $classMetadata->dynamic); } $response = $elasticaType->setMapping($elasticaTypeMapping); } catch (\Exception $e) { return $e->getMessage(); } return 200 == $response->getStatus() ? true : $response->getError(); }