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