/** * @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); }
/** * @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); }