Skip to content

Commit

Permalink
add tests synchronize index method
Browse files Browse the repository at this point in the history
  • Loading branch information
floriansemm committed Nov 14, 2016
1 parent 0b3c35c commit 6099dec
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions Tests/SolrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

namespace FS\SolrBundle\Tests;

use FS\SolrBundle\Doctrine\Annotation\AnnotationReader;
use FS\SolrBundle\Doctrine\Mapper\MetaInformationFactory;
use FS\SolrBundle\Tests\Doctrine\Annotation\Entities\InvalidTestEntityFiltered;
use FS\SolrBundle\Tests\Doctrine\Annotation\Entities\ValidTestEntityFiltered;
use FS\SolrBundle\Tests\Doctrine\Mapper\EntityCore0;
use FS\SolrBundle\Tests\Doctrine\Mapper\EntityCore1;
use FS\SolrBundle\Tests\Doctrine\Mapper\SolrDocumentStub;
use FS\SolrBundle\Tests\ResultFake;
use FS\SolrBundle\Tests\SolrResponseFake;
Expand All @@ -18,6 +22,7 @@
use FS\SolrBundle\Tests\Doctrine\Annotation\Entities\ValidEntityRepository;
use FS\SolrBundle\Tests\Util\CommandFactoryStub;
use FS\SolrBundle\Query\SolrQuery;
use Solarium\Plugin\BufferedAdd\BufferedAdd;
use Solarium\QueryType\Update\Query\Document\Document;

/**
Expand Down Expand Up @@ -247,6 +252,64 @@ public function testAddEntity_FilteredEntityWithUnknownCallback()
$solr->addDocument(new InvalidTestEntityFiltered());
}

/**
* @test
*/
public function indexDocumentsGroupedByCore()
{
$entity = new ValidTestEntity();
$entity->setTitle('title field');

$bufferPlugin = $this->getMock(BufferedAdd::class, array(), array(), '', false);

$bufferPlugin->expects($this->once())
->method('setEndpoint')
->with(null);

$bufferPlugin->expects($this->once())
->method('commit');

$this->solrClientFake->expects($this->once())
->method('getPlugin')
->with('bufferedadd')
->will($this->returnValue($bufferPlugin));

$solr = new Solr($this->solrClientFake, $this->eventDispatcher, new MetaInformationFactory(new AnnotationReader(new \Doctrine\Common\Annotations\AnnotationReader())), $this->mapper);
$solr->synchronizeIndex(array($entity));
}

/**
* @test
*/
public function setCoreToNullIfNoIndexExists()
{
$entity1 = new EntityCore0();
$entity1->setText('a text');

$entity2 = new EntityCore1();
$entity2->setText('a text');

$bufferPlugin = $this->getMock(BufferedAdd::class, array(), array(), '', false);

$bufferPlugin->expects($this->at(2))
->method('setEndpoint')
->with('core0');

$bufferPlugin->expects($this->at(5))
->method('setEndpoint')
->with('core1');

$bufferPlugin->expects($this->exactly(2))
->method('commit');

$this->solrClientFake->expects($this->once())
->method('getPlugin')
->with('bufferedadd')
->will($this->returnValue($bufferPlugin));

$solr = new Solr($this->solrClientFake, $this->eventDispatcher, new MetaInformationFactory(new AnnotationReader(new \Doctrine\Common\Annotations\AnnotationReader())), $this->mapper);
$solr->synchronizeIndex(array($entity1, $entity2));
}
}


Expand Down

0 comments on commit 6099dec

Please sign in to comment.