1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace GBProd\ElasticaProviderBundle\Test; |
4
|
|
|
|
5
|
|
|
use Elastica\Client; |
6
|
|
|
use GBProd\ElasticaProviderBundle\Provider\Provider; |
7
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Abstract base for unit tests bulk providers |
11
|
|
|
* |
12
|
|
|
* @author gbprod <[email protected]> |
13
|
|
|
*/ |
14
|
|
|
abstract class BulkProviderTestCase extends \PHPUnit_Framework_TestCase |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* Assert that provider will run index with data |
18
|
|
|
* |
19
|
|
|
* @param Provider $provider |
20
|
|
|
* @param string $id |
21
|
|
|
* @param array|null $data |
22
|
|
|
* |
23
|
|
|
* @return void |
24
|
|
|
*/ |
25
|
|
|
protected function assertWillIndex(Provider $provider, $id, array $data = null) |
26
|
|
|
{ |
27
|
|
|
$this->assertWillBulkWith( |
28
|
|
|
$provider, |
29
|
|
|
[ |
30
|
|
|
$this->createActionData('index', $id), |
31
|
|
|
$data, |
32
|
|
|
] |
33
|
|
|
); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
private function assertWillBulkWith(Provider $provider, array $data = null) |
37
|
|
|
{ |
38
|
|
|
$client = $this |
39
|
|
|
->getMockBuilder(Client::class) |
40
|
|
|
->disableOriginalConstructor() |
41
|
|
|
->getMock() |
42
|
|
|
; |
43
|
|
|
|
44
|
|
|
$client |
45
|
|
|
->expects($this->once()) |
46
|
|
|
->method('bulk') |
47
|
|
|
->with($data) |
48
|
|
|
; |
49
|
|
|
|
50
|
|
|
$provider->run( |
51
|
|
|
$client, |
52
|
|
|
'index', |
53
|
|
|
'type', |
54
|
|
|
$this->getMock(EventDispatcherInterface::class) |
55
|
|
|
); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
private function createActionData($action, $id) |
59
|
|
|
{ |
60
|
|
|
return [ |
61
|
|
|
$action => [ |
62
|
|
|
'_index' => 'index', |
63
|
|
|
'_type' => 'type', |
64
|
|
|
'_id' => $id, |
65
|
|
|
] |
66
|
|
|
]; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Assert that provider will run delete |
71
|
|
|
* |
72
|
|
|
* @param Provider $provider |
73
|
|
|
* @param string $id |
74
|
|
|
* |
75
|
|
|
* @return void |
76
|
|
|
*/ |
77
|
|
|
protected function assertWillDelete(Provider $provider, $id) |
78
|
|
|
{ |
79
|
|
|
$this->assertWillBulkWith( |
80
|
|
|
$provider, |
81
|
|
|
[ |
82
|
|
|
$this->createActionData('delete', $id) |
83
|
|
|
] |
84
|
|
|
); |
85
|
|
|
|
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Assert that provider will run update with data |
90
|
|
|
* |
91
|
|
|
* @param Provider $provider |
92
|
|
|
* @param string $id |
93
|
|
|
* @param array|null $data |
94
|
|
|
* |
95
|
|
|
* @return void |
96
|
|
|
*/ |
97
|
|
|
protected function assertWillUpdate(Provider $provider, $id, array $data = null) |
98
|
|
|
{ |
99
|
|
|
$this->assertWillBulkWith( |
100
|
|
|
$provider, |
101
|
|
|
[ |
102
|
|
|
$this->createActionData('update', $id), |
103
|
|
|
$data, |
104
|
|
|
] |
105
|
|
|
); |
106
|
|
|
|
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Assert that provider will run create with data |
111
|
|
|
* |
112
|
|
|
* @param Provider $provider |
113
|
|
|
* @param string $id |
114
|
|
|
* @param array|null $data |
115
|
|
|
* |
116
|
|
|
* @return void |
117
|
|
|
*/ |
118
|
|
|
protected function assertWillCreate(Provider $provider, $id, array $data = null) |
119
|
|
|
{ |
120
|
|
|
$this->assertWillBulkWith( |
121
|
|
|
$provider, |
122
|
|
|
[ |
123
|
|
|
$this->createActionData('create', $id), |
124
|
|
|
$data, |
125
|
|
|
] |
126
|
|
|
); |
127
|
|
|
|
128
|
|
|
} |
129
|
|
|
} |