Skip to content

Commit 6099dec

Browse files
author
floriansemm
committed
add tests synchronize index method
1 parent 0b3c35c commit 6099dec

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

Tests/SolrTest.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22

33
namespace FS\SolrBundle\Tests;
44

5+
use FS\SolrBundle\Doctrine\Annotation\AnnotationReader;
6+
use FS\SolrBundle\Doctrine\Mapper\MetaInformationFactory;
57
use FS\SolrBundle\Tests\Doctrine\Annotation\Entities\InvalidTestEntityFiltered;
68
use FS\SolrBundle\Tests\Doctrine\Annotation\Entities\ValidTestEntityFiltered;
9+
use FS\SolrBundle\Tests\Doctrine\Mapper\EntityCore0;
10+
use FS\SolrBundle\Tests\Doctrine\Mapper\EntityCore1;
711
use FS\SolrBundle\Tests\Doctrine\Mapper\SolrDocumentStub;
812
use FS\SolrBundle\Tests\ResultFake;
913
use FS\SolrBundle\Tests\SolrResponseFake;
@@ -18,6 +22,7 @@
1822
use FS\SolrBundle\Tests\Doctrine\Annotation\Entities\ValidEntityRepository;
1923
use FS\SolrBundle\Tests\Util\CommandFactoryStub;
2024
use FS\SolrBundle\Query\SolrQuery;
25+
use Solarium\Plugin\BufferedAdd\BufferedAdd;
2126
use Solarium\QueryType\Update\Query\Document\Document;
2227

2328
/**
@@ -247,6 +252,64 @@ public function testAddEntity_FilteredEntityWithUnknownCallback()
247252
$solr->addDocument(new InvalidTestEntityFiltered());
248253
}
249254

255+
/**
256+
* @test
257+
*/
258+
public function indexDocumentsGroupedByCore()
259+
{
260+
$entity = new ValidTestEntity();
261+
$entity->setTitle('title field');
262+
263+
$bufferPlugin = $this->getMock(BufferedAdd::class, array(), array(), '', false);
264+
265+
$bufferPlugin->expects($this->once())
266+
->method('setEndpoint')
267+
->with(null);
268+
269+
$bufferPlugin->expects($this->once())
270+
->method('commit');
271+
272+
$this->solrClientFake->expects($this->once())
273+
->method('getPlugin')
274+
->with('bufferedadd')
275+
->will($this->returnValue($bufferPlugin));
276+
277+
$solr = new Solr($this->solrClientFake, $this->eventDispatcher, new MetaInformationFactory(new AnnotationReader(new \Doctrine\Common\Annotations\AnnotationReader())), $this->mapper);
278+
$solr->synchronizeIndex(array($entity));
279+
}
280+
281+
/**
282+
* @test
283+
*/
284+
public function setCoreToNullIfNoIndexExists()
285+
{
286+
$entity1 = new EntityCore0();
287+
$entity1->setText('a text');
288+
289+
$entity2 = new EntityCore1();
290+
$entity2->setText('a text');
291+
292+
$bufferPlugin = $this->getMock(BufferedAdd::class, array(), array(), '', false);
293+
294+
$bufferPlugin->expects($this->at(2))
295+
->method('setEndpoint')
296+
->with('core0');
297+
298+
$bufferPlugin->expects($this->at(5))
299+
->method('setEndpoint')
300+
->with('core1');
301+
302+
$bufferPlugin->expects($this->exactly(2))
303+
->method('commit');
304+
305+
$this->solrClientFake->expects($this->once())
306+
->method('getPlugin')
307+
->with('bufferedadd')
308+
->will($this->returnValue($bufferPlugin));
309+
310+
$solr = new Solr($this->solrClientFake, $this->eventDispatcher, new MetaInformationFactory(new AnnotationReader(new \Doctrine\Common\Annotations\AnnotationReader())), $this->mapper);
311+
$solr->synchronizeIndex(array($entity1, $entity2));
312+
}
250313
}
251314

252315

0 commit comments

Comments
 (0)