/** * @Given /^I have a Doctrine entity$/ */ public function iHaveADoctrineEntity() { $this->solr = $this->getSolrInstance(); $this->entity = new ValidTestEntity(); $this->entity->setId(EntityIdentifier::generate()); $this->entity->setText('a Text'); }
/** * @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()); }
/** * @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; }
/** * @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); }