Ejemplo n.º 1
0
 /**
  * @Then /^I should not find the entity in Solr$/
  */
 public function iShouldNotFindTheEntityInSolr()
 {
     $client = $this->getSolrClient();
     $entityId = $this->entity->getId();
     $query = $client->createSelect();
     $query->setQuery(sprintf('id:%s', $entityId));
     $resultset = $client->select($query);
     if ($resultset->getNumFound() > 0) {
         throw new \RuntimeException(sprintf('document with id %s should not found in the index', $entityId));
     }
 }
Ejemplo n.º 2
0
 /**
  * @test
  */
 public function resultFromSuccessEventContainsNoMessage()
 {
     $entity = new ValidTestEntity();
     $entity->setId(1);
     $metaInformation = new MetaInformation();
     $metaInformation->setClassName('an entity');
     $metaInformation->setEntity($entity);
     $event = new Event(null, $metaInformation, '');
     $factory = new ConsoleResultFactory();
     $result = $factory->fromEvent($event);
     $this->assertEquals(1, $result->getResultId());
     $this->assertEquals('an entity', $result->getEntityClassname());
     $this->assertEquals('', $result->getErrorMessage());
 }
Ejemplo n.º 3
0
 /**
  * @test
  */
 public function doNotOverwriteComplexTypes_Relation()
 {
     $obj = new SolrDocumentStub(array('id' => 'document_1', 'title_t' => 'foo', 'posts_ss' => array('title 1', 'title2')));
     $entity1 = new ValidTestEntity();
     $entity1->setTitle('title 1');
     $entity = new ValidTestEntityWithRelation();
     $entity->setRelation($entity1);
     $metainformations = new MetaInformationFactory($this->reader);
     $metainformations = $metainformations->loadInformation($entity);
     $hydrator = new ValueHydrator();
     $hydratedDocument = $hydrator->hydrate($obj, $metainformations);
     $this->assertTrue($hydratedDocument instanceof $entity);
     $this->assertEquals(1, $entity->getId());
     $this->assertEquals('foo', $entity->getTitle());
     $this->assertTrue($hydratedDocument->getRelation() === $entity1);
 }
 /**
  * @return MetaInformation
  */
 public static function getMetaInformation()
 {
     $entity = new ValidTestEntity();
     $entity->setId(2);
     $metaInformation = new MetaInformation();
     $title = new Field(array('name' => 'title', 'type' => 'string', 'boost' => '1.8'));
     $text = new Field(array('name' => 'text', 'type' => 'text'));
     $createdAt = new Field(array('name' => 'created_at', 'type' => 'date', 'boost' => '1'));
     $metaInformation->setFields(array($title, $text, $createdAt));
     $fieldMapping = array('id' => 'id', 'title_s' => 'title', 'text_t' => 'text', 'created_at_dt' => 'created_at');
     $metaInformation->setBoost(1);
     $metaInformation->setFieldMapping($fieldMapping);
     $metaInformation->setEntity($entity);
     $metaInformation->setDocumentName('validtestentity');
     $metaInformation->setClassName(get_class($entity));
     return $metaInformation;
 }
Ejemplo n.º 5
0
 /**
  * @test
  */
 public function entityFromDbNotFoundShouldNotModifyMetainformations()
 {
     $repository = $this->getMock('Doctrine\\Common\\Persistence\\ObjectRepository');
     $repository->expects($this->once())->method('find')->with(1)->will($this->returnValue(null));
     $entity = new ValidTestEntity();
     $entity->setId(1);
     $metainformations = new MetaInformationFactory($this->reader);
     $metainformations = $metainformations->loadInformation($entity);
     $doctrineRegistry = $this->setupDoctrineRegistry($metainformations, $repository);
     $obj = new SolrDocumentStub(array());
     $obj->id = 'document_1';
     $hydrator = $this->getMock('FS\\SolrBundle\\Doctrine\\Hydration\\HydratorInterface');
     $hydrator->expects($this->once())->method('hydrate')->with($obj, $metainformations)->will($this->returnValue($entity));
     $doctrine = new DoctrineHydrator($doctrineRegistry, $hydrator);
     $hydratedDocument = $doctrine->hydrate($obj, $metainformations);
     $this->assertEquals($metainformations->getEntity(), $entity);
     $this->assertEquals($entity, $hydratedDocument);
 }
 /**
  * @test
  */
 public function mapRelationField_Getter()
 {
     $command = new MapAllFieldsCommand(new MetaInformationFactory($this->reader));
     $entity2 = new ValidTestEntity();
     $entity2->setTitle('embedded object');
     $entity1 = new ValidTestEntityWithRelation();
     $entity1->setTitle('title 1');
     $entity1->setText('text 1');
     $entity1->setRelation($entity2);
     $metaInformation = MetaTestInformationFactory::getMetaInformation($entity1);
     $fields = $metaInformation->getFields();
     $fields[] = new Field(array('name' => 'relation', 'type' => 'strings', 'boost' => '1', 'value' => $entity2, 'getter' => 'getTitle'));
     $metaInformation->setFields($fields);
     $actual = $command->createDocument($metaInformation);
     $this->assertArrayHasKey('relation_ss', $actual->getFields());
     $collectionField = $actual->getFields()['relation_ss'];
     $this->assertEquals('embedded object', $collectionField);
 }