public function testCreateDocument_DocumentHasOnlyIdAndNameField()
 {
     $command = new MapIdentifierCommand();
     $document = $command->createDocument(MetaTestInformationFactory::getMetaInformation());
     $this->assertEquals(2, $document->getFieldCount(), 'fieldcount is two');
     $this->assertEquals(2, $document->getField('id')->values[0], 'id is 2');
 }
Example #2
0
 private function setupMetaFactoryLoadOneCompleteInformation($metaInformation = null)
 {
     if (null === $metaInformation) {
         $metaInformation = MetaTestInformationFactory::getMetaInformation();
     }
     $this->metaFactory->expects($this->once())->method('loadInformation')->will($this->returnValue($metaInformation));
 }
 public function testCreateDocument_DocumentHasOnlyIdAndNameField()
 {
     $command = new MapIdentifierCommand();
     $document = $command->createDocument(MetaTestInformationFactory::getMetaInformation());
     $this->assertEquals(1, $document->count(), 'fieldcount is two');
     $this->assertEquals('validtestentity_2', $document->id, 'id is 2');
 }
Example #4
0
 public function testToDocument_DocumentIsUpdated()
 {
     $mapper = new \FS\SolrBundle\Doctrine\Mapper\EntityMapper();
     $mapper->setMappingCommand(new MapAllFieldsCommand(new AnnotationReader()));
     $actual = $mapper->toDocument(MetaTestInformationFactory::getMetaInformation());
     $this->assertTrue($actual instanceof \SolrInputDocument);
     $this->assertTrue($actual->fieldExists('id'));
 }
Example #5
0
 public function testToDocument_DocumentIsUpdated()
 {
     $mapper = new \FS\SolrBundle\Doctrine\Mapper\EntityMapper($this->doctrineHydrator, $this->indexHydrator);
     $mapper->setMappingCommand(new MapAllFieldsCommand(new AnnotationReader()));
     $actual = $mapper->toDocument(MetaTestInformationFactory::getMetaInformation());
     $this->assertTrue($actual instanceof Document);
     $this->assertNotNull($actual->id);
 }
 public function testMapEntity_DocumentShouldContainThreeFields()
 {
     $command = new MapAllFieldsCommand();
     $actual = $command->createDocument(MetaTestInformationFactory::getMetaInformation());
     $this->assertTrue($actual instanceof \SolrInputDocument, 'is a SolrInputDocument');
     $this->assertFieldCount(3, $actual, 'three fields are mapped');
     $this->assertEquals(1, $actual->getBoost(), 'document boost should be 1');
     $boostTitleField = $actual->getField('title_s')->boost;
     $this->assertEquals(1.8, $boostTitleField, 'boost value of field title_s should be 1.8');
     $this->assertHasDocumentFields($actual, self::$MAPPED_FIELDS);
 }
Example #7
0
 /**
  * @test
  */
 public function removeDocumentFromAllCores()
 {
     $metaInformation = MetaTestInformationFactory::getMetaInformation();
     $metaInformation->setIndex('*');
     $this->setupMetaFactoryLoadOneCompleteInformation($metaInformation);
     $this->mapper->expects($this->once())->method('toDocument')->will($this->returnValue(new DocumentStub()));
     $this->solrClientFake->expects($this->once())->method('getEndpoints')->will($this->returnValue(array('core0' => array(), 'core1' => array())));
     $deleteQuery = $this->getMock('Solarium\\QueryType\\Update\\Query\\Query', array(), array(), '', false);
     $deleteQuery->expects($this->once())->method('addDeleteQuery')->with($this->isType('string'));
     $deleteQuery->expects($this->once())->method('addCommit');
     $this->solrClientFake->expects($this->once())->method('createUpdate')->will($this->returnValue($deleteQuery));
     $this->solrClientFake->expects($this->exactly(2))->method('update');
     $solr = new Solr($this->solrClientFake, $this->commandFactory, $this->eventDispatcher, $this->metaFactory, $this->mapper);
     $solr->removeDocument(new ValidTestEntity());
 }
Example #8
0
 public function testFindBy()
 {
     $fields = array('title' => 'foo', 'text' => 'bar');
     $metaFactory = $this->getMock('FS\\SolrBundle\\Doctrine\\Mapper\\MetaInformationFactory', array(), array(), '', false);
     $metaFactory->expects($this->once())->method('loadInformation')->will($this->returnValue(MetaTestInformationFactory::getMetaInformation()));
     $solr = $this->getMock('FS\\SolrBundle\\Solr', array(), array(), '', false);
     $query = $this->getMock('FS\\SolrBundle\\Query\\SolrQuery', array(), array(), '', false);
     $query->expects($this->exactly(3))->method('addSearchTerm');
     $query->expects($this->once())->method('getHelper')->will($this->returnValue(new Helper()));
     $solr->expects($this->once())->method('createQuery')->will($this->returnValue($query));
     $solr->expects($this->once())->method('query')->with($query)->will($this->returnValue(array()));
     $solr->expects($this->once())->method('getMetaFactory')->will($this->returnValue($metaFactory));
     $entity = new ValidTestEntity();
     $repo = new Repository($solr, $entity);
     $found = $repo->findBy($fields);
     $this->assertTrue(is_array($found));
 }
Example #9
0
 public function testFindAll()
 {
     $document = new \SolrInputDocument();
     $document->addField('id', 2);
     $document->addField('document_name_s', 'post');
     $metaFactory = $this->getMock('FS\\SolrBundle\\Doctrine\\Mapper\\MetaInformationFactory', array(), array(), '', false);
     $metaFactory->expects($this->once())->method('loadInformation')->will($this->returnValue(MetaTestInformationFactory::getMetaInformation()));
     $mapper = $this->getMock('FS\\SolrBundle\\Doctrine\\Mapper\\EntityMapper');
     $mapper->expects($this->once())->method('toDocument')->will($this->returnValue($document));
     $solr = $this->getMock('FS\\SolrBundle\\SolrFacade', array(), array(), '', false);
     $solr->expects($this->once())->method('getMapper')->will($this->returnValue($mapper));
     $solr->expects($this->once())->method('getCommandFactory')->will($this->returnValue(CommandFactoryStub::getFactoryWithAllMappingCommand()));
     $solr->expects($this->once())->method('getMetaFactory')->will($this->returnValue($metaFactory));
     $entity = new ValidTestEntity();
     $solr->expects($this->once())->method('query')->will($this->returnValue(array($entity)));
     $repo = new Repository($solr, $entity);
     $actual = $repo->findAll();
     $this->assertTrue(is_array($actual));
     $this->assertFalse($document->fieldExists('id'), 'id was removed');
 }
 /**
  * @test
  */
 public function callGetterWithParameters()
 {
     $command = new MapAllFieldsCommand(new MetaInformationFactory($this->reader));
     $entity1 = new ValidTestEntity();
     $metaInformation = MetaTestInformationFactory::getMetaInformation($entity1);
     $metaInformation->setFields(array(new Field(array('name' => 'test_field', 'type' => 'datetime', 'boost' => '1', 'value' => new TestObject(), 'getter' => "testGetter('string3', 'string1', 'string')"))));
     $fields = $metaInformation->getFields();
     $metaInformation->setFields($fields);
     $actual = $command->createDocument($metaInformation);
     $fields = $actual->getFields();
     $this->assertArrayHasKey('test_field_dt', $fields);
     $this->assertEquals(array('string3', 'string1', 'string'), $fields['test_field_dt']);
 }
Example #11
0
 /**
  * @expectedException \BadMethodCallException
  */
 public function testAddEntity_FilteredEntityWithUnknownCallback()
 {
     $this->assertUpdateQueryWasNotExecuted();
     $this->eventDispatcher->expects($this->never())->method('dispatch');
     $information = MetaTestInformationFactory::getMetaInformation();
     $information->setSynchronizationCallback('shouldBeIndex');
     $this->setupMetaFactoryLoadOneCompleteInformation($information);
     $solr = new Solr($this->solrClientFake, $this->commandFactory, $this->eventDispatcher, $this->metaFactory, $this->mapper);
     $solr->addDocument(new InvalidTestEntityFiltered());
 }