@@ -14,281 +14,281 @@ |
||
14 | 14 | */ |
15 | 15 | class BulkDataProviderTest extends \PHPUnit_Framework_TestCase |
16 | 16 | { |
17 | - public function testRunExecutePopulate() |
|
18 | - { |
|
19 | - $provider = $this->getMockForAbstractClass(BulkDataProvider::class); |
|
20 | - |
|
21 | - $provider |
|
22 | - ->expects($this->once()) |
|
23 | - ->method('populate') |
|
24 | - ; |
|
25 | - |
|
26 | - $provider->run( |
|
27 | - $this->getClient('index'), |
|
28 | - 'index', |
|
29 | - 'type', |
|
30 | - $this->getMock(EventDispatcherInterface::class) |
|
31 | - ); |
|
32 | - } |
|
33 | - |
|
34 | - /** |
|
35 | - * @return Client |
|
36 | - */ |
|
37 | - private function getClient($index) |
|
38 | - { |
|
39 | - $client = $this |
|
40 | - ->getMockBuilder(Client::class) |
|
41 | - ->disableOriginalConstructor() |
|
42 | - ->getMock() |
|
43 | - ; |
|
44 | - |
|
45 | - $client |
|
46 | - ->expects($this->any()) |
|
47 | - ->method('indices') |
|
48 | - ->willReturn( |
|
17 | + public function testRunExecutePopulate() |
|
18 | + { |
|
19 | + $provider = $this->getMockForAbstractClass(BulkDataProvider::class); |
|
20 | + |
|
21 | + $provider |
|
22 | + ->expects($this->once()) |
|
23 | + ->method('populate') |
|
24 | + ; |
|
25 | + |
|
26 | + $provider->run( |
|
27 | + $this->getClient('index'), |
|
28 | + 'index', |
|
29 | + 'type', |
|
30 | + $this->getMock(EventDispatcherInterface::class) |
|
31 | + ); |
|
32 | + } |
|
33 | + |
|
34 | + /** |
|
35 | + * @return Client |
|
36 | + */ |
|
37 | + private function getClient($index) |
|
38 | + { |
|
39 | + $client = $this |
|
40 | + ->getMockBuilder(Client::class) |
|
41 | + ->disableOriginalConstructor() |
|
42 | + ->getMock() |
|
43 | + ; |
|
44 | + |
|
45 | + $client |
|
46 | + ->expects($this->any()) |
|
47 | + ->method('indices') |
|
48 | + ->willReturn( |
|
49 | 49 | $this->newIndicesExpectingRefresh($index) |
50 | - ) |
|
51 | - ; |
|
52 | - |
|
53 | - return $client; |
|
54 | - } |
|
55 | - |
|
56 | - private function newIndicesExpectingRefresh($index) |
|
57 | - { |
|
58 | - $indices = $this |
|
59 | - ->getMockBuilder(IndicesNamespace::class) |
|
60 | - ->disableOriginalConstructor() |
|
61 | - ->getMock() |
|
62 | - ; |
|
63 | - |
|
64 | - $indices |
|
65 | - ->expects($this->once()) |
|
66 | - ->method('refresh') |
|
67 | - ->with([ |
|
50 | + ) |
|
51 | + ; |
|
52 | + |
|
53 | + return $client; |
|
54 | + } |
|
55 | + |
|
56 | + private function newIndicesExpectingRefresh($index) |
|
57 | + { |
|
58 | + $indices = $this |
|
59 | + ->getMockBuilder(IndicesNamespace::class) |
|
60 | + ->disableOriginalConstructor() |
|
61 | + ->getMock() |
|
62 | + ; |
|
63 | + |
|
64 | + $indices |
|
65 | + ->expects($this->once()) |
|
66 | + ->method('refresh') |
|
67 | + ->with([ |
|
68 | 68 | 'index' => $index, |
69 | - ]) |
|
70 | - ; |
|
69 | + ]) |
|
70 | + ; |
|
71 | 71 | |
72 | - return $indices; |
|
73 | - } |
|
72 | + return $indices; |
|
73 | + } |
|
74 | 74 | |
75 | - public function testIndexWithIndexAndType() |
|
76 | - { |
|
77 | - $client = $this->newClientExpectingBulk( |
|
78 | - [ |
|
75 | + public function testIndexWithIndexAndType() |
|
76 | + { |
|
77 | + $client = $this->newClientExpectingBulk( |
|
78 | + [ |
|
79 | 79 | 'body' => |
80 | 80 | [ |
81 | - [ |
|
82 | - 'index' => [ |
|
83 | - '_index' => 'my_index', |
|
84 | - '_type' => 'my_type', |
|
85 | - '_id' => 'my_id', |
|
86 | - ] |
|
87 | - ], |
|
88 | - [ |
|
89 | - 'foo' => 'bar', |
|
90 | - ] |
|
81 | + [ |
|
82 | + 'index' => [ |
|
83 | + '_index' => 'my_index', |
|
84 | + '_type' => 'my_type', |
|
85 | + '_id' => 'my_id', |
|
86 | + ] |
|
87 | + ], |
|
88 | + [ |
|
89 | + 'foo' => 'bar', |
|
90 | + ] |
|
91 | + ] |
|
91 | 92 | ] |
92 | - ] |
|
93 | - ); |
|
94 | - |
|
95 | - $provider = $this->getMockForAbstractClass(BulkDataProvider::class); |
|
96 | - $provider |
|
97 | - ->expects($this->once()) |
|
98 | - ->method('populate') |
|
99 | - ->will( |
|
93 | + ); |
|
94 | + |
|
95 | + $provider = $this->getMockForAbstractClass(BulkDataProvider::class); |
|
96 | + $provider |
|
97 | + ->expects($this->once()) |
|
98 | + ->method('populate') |
|
99 | + ->will( |
|
100 | 100 | $this->returnCallback( |
101 | - function () use ($provider) { |
|
102 | - $provider->index( |
|
103 | - 'my_id', |
|
104 | - ['foo' => 'bar'] |
|
105 | - ); |
|
106 | - } |
|
101 | + function () use ($provider) { |
|
102 | + $provider->index( |
|
103 | + 'my_id', |
|
104 | + ['foo' => 'bar'] |
|
105 | + ); |
|
106 | + } |
|
107 | + ) |
|
107 | 108 | ) |
108 | - ) |
|
109 | - ; |
|
110 | - |
|
111 | - $provider->run( |
|
112 | - $client, |
|
113 | - 'my_index', |
|
114 | - 'my_type', |
|
115 | - $this->getMock(EventDispatcherInterface::class) |
|
116 | - ); |
|
117 | - } |
|
118 | - |
|
119 | - private function newClientExpectingBulk($content) |
|
120 | - { |
|
121 | - $client = $this->getClient('my_index'); |
|
122 | - |
|
123 | - $client |
|
124 | - ->expects($this->once()) |
|
125 | - ->method('bulk') |
|
126 | - ->with($content) |
|
127 | - ; |
|
128 | - |
|
129 | - return $client; |
|
130 | - } |
|
131 | - |
|
132 | - public function testIndexRunBulkTwiceIfMoreThanBatchSize() |
|
133 | - { |
|
134 | - $provider = $this->getMockForAbstractClass(BulkDataProvider::class); |
|
135 | - |
|
136 | - $client = $this->getClient('my_index'); |
|
137 | - $client |
|
138 | - ->expects($this->exactly(3)) |
|
139 | - ->method('bulk') |
|
140 | - ; |
|
141 | - |
|
142 | - $provider->changeBulkSize(50); |
|
143 | - $provider |
|
144 | - ->expects($this->once()) |
|
145 | - ->method('populate') |
|
146 | - ->will( |
|
109 | + ; |
|
110 | + |
|
111 | + $provider->run( |
|
112 | + $client, |
|
113 | + 'my_index', |
|
114 | + 'my_type', |
|
115 | + $this->getMock(EventDispatcherInterface::class) |
|
116 | + ); |
|
117 | + } |
|
118 | + |
|
119 | + private function newClientExpectingBulk($content) |
|
120 | + { |
|
121 | + $client = $this->getClient('my_index'); |
|
122 | + |
|
123 | + $client |
|
124 | + ->expects($this->once()) |
|
125 | + ->method('bulk') |
|
126 | + ->with($content) |
|
127 | + ; |
|
128 | + |
|
129 | + return $client; |
|
130 | + } |
|
131 | + |
|
132 | + public function testIndexRunBulkTwiceIfMoreThanBatchSize() |
|
133 | + { |
|
134 | + $provider = $this->getMockForAbstractClass(BulkDataProvider::class); |
|
135 | + |
|
136 | + $client = $this->getClient('my_index'); |
|
137 | + $client |
|
138 | + ->expects($this->exactly(3)) |
|
139 | + ->method('bulk') |
|
140 | + ; |
|
141 | + |
|
142 | + $provider->changeBulkSize(50); |
|
143 | + $provider |
|
144 | + ->expects($this->once()) |
|
145 | + ->method('populate') |
|
146 | + ->will( |
|
147 | 147 | $this->returnCallback( |
148 | - function () use ($provider) { |
|
149 | - for($i = 0; $i < 150; $i++) { |
|
150 | - $provider->index( |
|
148 | + function () use ($provider) { |
|
149 | + for($i = 0; $i < 150; $i++) { |
|
150 | + $provider->index( |
|
151 | 151 | 'my_id', |
152 | 152 | ['foo' => 'bar'] |
153 | - ); |
|
154 | - } |
|
155 | - } |
|
153 | + ); |
|
154 | + } |
|
155 | + } |
|
156 | + ) |
|
156 | 157 | ) |
157 | - ) |
|
158 | - ; |
|
159 | - |
|
160 | - $provider->run( |
|
161 | - $client, |
|
162 | - 'my_index', |
|
163 | - 'my_type', |
|
164 | - $this->getMock(EventDispatcherInterface::class) |
|
165 | - ); |
|
166 | - } |
|
167 | - |
|
168 | - public function testCountIsNull() |
|
169 | - { |
|
170 | - $provider = $this->getMockForAbstractClass(BulkDataProvider::class); |
|
171 | - |
|
172 | - $this->assertNull($provider->count()); |
|
173 | - } |
|
174 | - |
|
175 | - public function testDelete() |
|
176 | - { |
|
177 | - $client = $this->newClientExpectingBulk( |
|
178 | - [ |
|
158 | + ; |
|
159 | + |
|
160 | + $provider->run( |
|
161 | + $client, |
|
162 | + 'my_index', |
|
163 | + 'my_type', |
|
164 | + $this->getMock(EventDispatcherInterface::class) |
|
165 | + ); |
|
166 | + } |
|
167 | + |
|
168 | + public function testCountIsNull() |
|
169 | + { |
|
170 | + $provider = $this->getMockForAbstractClass(BulkDataProvider::class); |
|
171 | + |
|
172 | + $this->assertNull($provider->count()); |
|
173 | + } |
|
174 | + |
|
175 | + public function testDelete() |
|
176 | + { |
|
177 | + $client = $this->newClientExpectingBulk( |
|
178 | + [ |
|
179 | 179 | 'body' => |
180 | 180 | [ |
181 | - [ |
|
182 | - 'delete' => [ |
|
183 | - '_index' => 'my_index', |
|
184 | - '_type' => 'my_type', |
|
185 | - '_id' => 'my_id', |
|
186 | - ] |
|
187 | - ] |
|
181 | + [ |
|
182 | + 'delete' => [ |
|
183 | + '_index' => 'my_index', |
|
184 | + '_type' => 'my_type', |
|
185 | + '_id' => 'my_id', |
|
186 | + ] |
|
187 | + ] |
|
188 | + ] |
|
188 | 189 | ] |
189 | - ] |
|
190 | - ); |
|
191 | - |
|
192 | - $provider = $this->getMockForAbstractClass(BulkDataProvider::class); |
|
193 | - $provider |
|
194 | - ->expects($this->once()) |
|
195 | - ->method('populate') |
|
196 | - ->will( |
|
190 | + ); |
|
191 | + |
|
192 | + $provider = $this->getMockForAbstractClass(BulkDataProvider::class); |
|
193 | + $provider |
|
194 | + ->expects($this->once()) |
|
195 | + ->method('populate') |
|
196 | + ->will( |
|
197 | 197 | $this->returnCallback( |
198 | - function () use ($provider) { |
|
199 | - $provider->delete('my_id'); |
|
200 | - } |
|
198 | + function () use ($provider) { |
|
199 | + $provider->delete('my_id'); |
|
200 | + } |
|
201 | + ) |
|
201 | 202 | ) |
202 | - ) |
|
203 | - ; |
|
204 | - |
|
205 | - $provider->run( |
|
206 | - $client, |
|
207 | - 'my_index', |
|
208 | - 'my_type', |
|
209 | - $this->getMock(EventDispatcherInterface::class) |
|
210 | - ); |
|
211 | - } |
|
212 | - |
|
213 | - public function testCreate() |
|
214 | - { |
|
215 | - $client = $this->newClientExpectingBulk( |
|
216 | - [ |
|
203 | + ; |
|
204 | + |
|
205 | + $provider->run( |
|
206 | + $client, |
|
207 | + 'my_index', |
|
208 | + 'my_type', |
|
209 | + $this->getMock(EventDispatcherInterface::class) |
|
210 | + ); |
|
211 | + } |
|
212 | + |
|
213 | + public function testCreate() |
|
214 | + { |
|
215 | + $client = $this->newClientExpectingBulk( |
|
216 | + [ |
|
217 | 217 | 'body' => |
218 | 218 | [ |
219 | - [ |
|
220 | - 'create' => [ |
|
221 | - '_index' => 'my_index', |
|
222 | - '_type' => 'my_type', |
|
223 | - '_id' => 'my_id', |
|
224 | - ] |
|
225 | - ], |
|
226 | - [ |
|
227 | - 'foo' => 'bar', |
|
228 | - ] |
|
219 | + [ |
|
220 | + 'create' => [ |
|
221 | + '_index' => 'my_index', |
|
222 | + '_type' => 'my_type', |
|
223 | + '_id' => 'my_id', |
|
224 | + ] |
|
225 | + ], |
|
226 | + [ |
|
227 | + 'foo' => 'bar', |
|
228 | + ] |
|
229 | 229 | ] |
230 | - ] |
|
231 | - ); |
|
232 | - |
|
233 | - $provider = $this->getMockForAbstractClass(BulkDataProvider::class); |
|
234 | - $provider |
|
235 | - ->expects($this->once()) |
|
236 | - ->method('populate') |
|
237 | - ->will( |
|
230 | + ] |
|
231 | + ); |
|
232 | + |
|
233 | + $provider = $this->getMockForAbstractClass(BulkDataProvider::class); |
|
234 | + $provider |
|
235 | + ->expects($this->once()) |
|
236 | + ->method('populate') |
|
237 | + ->will( |
|
238 | 238 | $this->returnCallback( |
239 | - function () use ($provider) { |
|
240 | - $provider->create('my_id', ['foo' => 'bar']); |
|
241 | - } |
|
239 | + function () use ($provider) { |
|
240 | + $provider->create('my_id', ['foo' => 'bar']); |
|
241 | + } |
|
242 | 242 | ) |
243 | - ) |
|
244 | - ; |
|
245 | - |
|
246 | - $provider->run( |
|
247 | - $client, |
|
248 | - 'my_index', |
|
249 | - 'my_type', |
|
250 | - $this->getMock(EventDispatcherInterface::class) |
|
251 | - ); |
|
252 | - } |
|
253 | - |
|
254 | - public function testUpdate() |
|
255 | - { |
|
256 | - $client = $this->newClientExpectingBulk( |
|
257 | - [ |
|
243 | + ) |
|
244 | + ; |
|
245 | + |
|
246 | + $provider->run( |
|
247 | + $client, |
|
248 | + 'my_index', |
|
249 | + 'my_type', |
|
250 | + $this->getMock(EventDispatcherInterface::class) |
|
251 | + ); |
|
252 | + } |
|
253 | + |
|
254 | + public function testUpdate() |
|
255 | + { |
|
256 | + $client = $this->newClientExpectingBulk( |
|
257 | + [ |
|
258 | 258 | 'body' => |
259 | 259 | [ |
260 | - [ |
|
261 | - 'update' => [ |
|
262 | - '_index' => 'my_index', |
|
263 | - '_type' => 'my_type', |
|
264 | - '_id' => 'my_id', |
|
265 | - ] |
|
266 | - ], |
|
267 | - [ |
|
268 | - 'foo' => 'bar', |
|
269 | - ] |
|
260 | + [ |
|
261 | + 'update' => [ |
|
262 | + '_index' => 'my_index', |
|
263 | + '_type' => 'my_type', |
|
264 | + '_id' => 'my_id', |
|
265 | + ] |
|
266 | + ], |
|
267 | + [ |
|
268 | + 'foo' => 'bar', |
|
269 | + ] |
|
270 | + ] |
|
270 | 271 | ] |
271 | - ] |
|
272 | - ); |
|
273 | - |
|
274 | - $provider = $this->getMockForAbstractClass(BulkDataProvider::class); |
|
275 | - $provider |
|
276 | - ->expects($this->once()) |
|
277 | - ->method('populate') |
|
278 | - ->will( |
|
272 | + ); |
|
273 | + |
|
274 | + $provider = $this->getMockForAbstractClass(BulkDataProvider::class); |
|
275 | + $provider |
|
276 | + ->expects($this->once()) |
|
277 | + ->method('populate') |
|
278 | + ->will( |
|
279 | 279 | $this->returnCallback( |
280 | - function () use ($provider) { |
|
281 | - $provider->update('my_id', ['foo' => 'bar']); |
|
282 | - } |
|
280 | + function () use ($provider) { |
|
281 | + $provider->update('my_id', ['foo' => 'bar']); |
|
282 | + } |
|
283 | + ) |
|
283 | 284 | ) |
284 | - ) |
|
285 | - ; |
|
286 | - |
|
287 | - $provider->run( |
|
288 | - $client, |
|
289 | - 'my_index', |
|
290 | - 'my_type', |
|
291 | - $this->getMock(EventDispatcherInterface::class) |
|
292 | - ); |
|
293 | - } |
|
285 | + ; |
|
286 | + |
|
287 | + $provider->run( |
|
288 | + $client, |
|
289 | + 'my_index', |
|
290 | + 'my_type', |
|
291 | + $this->getMock(EventDispatcherInterface::class) |
|
292 | + ); |
|
293 | + } |
|
294 | 294 | } |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | ->method('populate') |
99 | 99 | ->will( |
100 | 100 | $this->returnCallback( |
101 | - function () use ($provider) { |
|
101 | + function() use ($provider) { |
|
102 | 102 | $provider->index( |
103 | 103 | 'my_id', |
104 | 104 | ['foo' => 'bar'] |
@@ -145,8 +145,8 @@ discard block |
||
145 | 145 | ->method('populate') |
146 | 146 | ->will( |
147 | 147 | $this->returnCallback( |
148 | - function () use ($provider) { |
|
149 | - for($i = 0; $i < 150; $i++) { |
|
148 | + function() use ($provider) { |
|
149 | + for ($i = 0; $i < 150; $i++) { |
|
150 | 150 | $provider->index( |
151 | 151 | 'my_id', |
152 | 152 | ['foo' => 'bar'] |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | ->method('populate') |
196 | 196 | ->will( |
197 | 197 | $this->returnCallback( |
198 | - function () use ($provider) { |
|
198 | + function() use ($provider) { |
|
199 | 199 | $provider->delete('my_id'); |
200 | 200 | } |
201 | 201 | ) |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | ->method('populate') |
237 | 237 | ->will( |
238 | 238 | $this->returnCallback( |
239 | - function () use ($provider) { |
|
239 | + function() use ($provider) { |
|
240 | 240 | $provider->create('my_id', ['foo' => 'bar']); |
241 | 241 | } |
242 | 242 | ) |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | ->method('populate') |
278 | 278 | ->will( |
279 | 279 | $this->returnCallback( |
280 | - function () use ($provider) { |
|
280 | + function() use ($provider) { |
|
281 | 281 | $provider->update('my_id', ['foo' => 'bar']); |
282 | 282 | } |
283 | 283 | ) |