1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Mdiyakov\DoctrineSolrBundle\Tests\Manager; |
4
|
|
|
|
5
|
|
|
use Mdiyakov\DoctrineSolrBundle\Manager\IndexProcessManager; |
6
|
|
|
|
7
|
|
|
class MyEntity {} |
8
|
|
|
|
9
|
|
|
class IndexProcessManagerTest extends \PHPUnit_Framework_TestCase |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject |
13
|
|
|
*/ |
14
|
|
|
private $indexerBuilder; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject |
18
|
|
|
*/ |
19
|
|
|
private $filterValidator; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject |
23
|
|
|
*/ |
24
|
|
|
private $indexer; |
25
|
|
|
|
26
|
|
|
public function setUp() |
27
|
|
|
{ |
28
|
|
|
$this->indexerBuilder = $this->getMockBuilder('Mdiyakov\DoctrineSolrBundle\Indexer\IndexerBuilder')->disableOriginalConstructor()->getMock(); |
29
|
|
|
$this->filterValidator = $this->getMockBuilder('Mdiyakov\DoctrineSolrBundle\Filter\FilterValidator')->disableOriginalConstructor()->getMock(); |
30
|
|
|
$this->indexer = $this->getMockBuilder('Mdiyakov\DoctrineSolrBundle\Indexer\Indexer')->disableOriginalConstructor()->getMock(); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function testReindex() |
34
|
|
|
{ |
35
|
|
|
$entity = new MyEntity(); |
36
|
|
|
$this->indexerBuilder->expects($this->once()) |
37
|
|
|
->method('createByEntityClass') |
38
|
|
|
->with(get_class($entity)) |
39
|
|
|
->will($this->returnValue($this->indexer)); |
40
|
|
|
|
41
|
|
|
$this->filterValidator->expects($this->once()) |
42
|
|
|
->method('validate') |
43
|
|
|
->with($entity); |
44
|
|
|
|
45
|
|
|
$this->indexer->expects($this->once()) |
46
|
|
|
->method('indexAllFields') |
47
|
|
|
->with($entity); |
48
|
|
|
|
49
|
|
|
$indexProcessManager = new IndexProcessManager($this->indexerBuilder, $this->filterValidator); |
50
|
|
|
$result = $indexProcessManager->reindex($entity); |
51
|
|
|
$this->assertEquals(true, $result->isSuccess()); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
public function testRemove() |
56
|
|
|
{ |
57
|
|
|
$entity = new MyEntity(); |
58
|
|
|
|
59
|
|
|
$this->indexerBuilder->expects($this->once()) |
60
|
|
|
->method('createByEntityClass') |
61
|
|
|
->with(get_class($entity)) |
62
|
|
|
->will($this->returnValue($this->indexer)); |
63
|
|
|
|
64
|
|
|
$this->indexer->expects($this->once()) |
65
|
|
|
->method('removeByPrimaryKey') |
66
|
|
|
->with($entity); |
67
|
|
|
|
68
|
|
|
$indexProcessManager = new IndexProcessManager($this->indexerBuilder, $this->filterValidator); |
69
|
|
|
$indexProcessManager->remove($entity); |
70
|
|
|
} |
71
|
|
|
} |