|
2 | 2 |
|
3 | 3 | namespace FS\SolrBundle\Tests; |
4 | 4 |
|
| 5 | +use FS\SolrBundle\Doctrine\Annotation\AnnotationReader; |
| 6 | +use FS\SolrBundle\Doctrine\Mapper\MetaInformationFactory; |
5 | 7 | use FS\SolrBundle\Tests\Doctrine\Annotation\Entities\InvalidTestEntityFiltered; |
6 | 8 | use FS\SolrBundle\Tests\Doctrine\Annotation\Entities\ValidTestEntityFiltered; |
| 9 | +use FS\SolrBundle\Tests\Doctrine\Mapper\EntityCore0; |
| 10 | +use FS\SolrBundle\Tests\Doctrine\Mapper\EntityCore1; |
7 | 11 | use FS\SolrBundle\Tests\Doctrine\Mapper\SolrDocumentStub; |
8 | 12 | use FS\SolrBundle\Tests\ResultFake; |
9 | 13 | use FS\SolrBundle\Tests\SolrResponseFake; |
|
18 | 22 | use FS\SolrBundle\Tests\Doctrine\Annotation\Entities\ValidEntityRepository; |
19 | 23 | use FS\SolrBundle\Tests\Util\CommandFactoryStub; |
20 | 24 | use FS\SolrBundle\Query\SolrQuery; |
| 25 | +use Solarium\Plugin\BufferedAdd\BufferedAdd; |
21 | 26 | use Solarium\QueryType\Update\Query\Document\Document; |
22 | 27 |
|
23 | 28 | /** |
@@ -247,6 +252,64 @@ public function testAddEntity_FilteredEntityWithUnknownCallback() |
247 | 252 | $solr->addDocument(new InvalidTestEntityFiltered()); |
248 | 253 | } |
249 | 254 |
|
| 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 | + } |
250 | 313 | } |
251 | 314 |
|
252 | 315 |
|
|
0 commit comments