3
3
namespace Enqueue \Dbal \Tests ;
4
4
5
5
use Doctrine \DBAL \Connection ;
6
+ use Doctrine \DBAL \Platforms \AbstractPlatform ;
7
+ use Doctrine \DBAL \Query \QueryBuilder ;
6
8
use Doctrine \DBAL \Statement ;
7
9
use Enqueue \Dbal \DbalConsumer ;
8
10
use Enqueue \Dbal \DbalContext ;
@@ -148,7 +150,41 @@ public function testShouldReceiveMessage()
148
150
->will ($ this ->returnValue ($ dbalMessage ))
149
151
;
150
152
153
+ $ queryBuilder = $ this ->createQueryBuilderMock ();
154
+ $ queryBuilder
155
+ ->expects ($ this ->once ())
156
+ ->method ('select ' )
157
+ ->will ($ this ->returnSelf ())
158
+ ;
159
+ $ queryBuilder
160
+ ->expects ($ this ->once ())
161
+ ->method ('from ' )
162
+ ->will ($ this ->returnSelf ())
163
+ ;
164
+ $ queryBuilder
165
+ ->expects ($ this ->once ())
166
+ ->method ('where ' )
167
+ ->will ($ this ->returnSelf ())
168
+ ;
169
+ $ queryBuilder
170
+ ->expects ($ this ->once ())
171
+ ->method ('andWhere ' )
172
+ ->will ($ this ->returnSelf ())
173
+ ;
174
+ $ queryBuilder
175
+ ->expects ($ this ->exactly (2 ))
176
+ ->method ('orderBy ' )
177
+ ->will ($ this ->returnSelf ())
178
+ ;
179
+
180
+ $ platform = $ this ->createPlatformMock ();
181
+
151
182
$ dbal = $ this ->createConnectionMock ();
183
+ $ dbal
184
+ ->expects ($ this ->once ())
185
+ ->method ('createQueryBuilder ' )
186
+ ->willReturn ($ queryBuilder )
187
+ ;
152
188
$ dbal
153
189
->expects ($ this ->once ())
154
190
->method ('executeQuery ' )
@@ -163,6 +199,11 @@ public function testShouldReceiveMessage()
163
199
->expects ($ this ->once ())
164
200
->method ('commit ' )
165
201
;
202
+ $ dbal
203
+ ->expects ($ this ->once ())
204
+ ->method ('getDatabasePlatform ' )
205
+ ->willReturn ($ platform )
206
+ ;
166
207
167
208
$ context = $ this ->createContextMock ();
168
209
$ context
@@ -201,7 +242,41 @@ public function testShouldReturnNullIfThereIsNoNewMessage()
201
242
->will ($ this ->returnValue (null ))
202
243
;
203
244
245
+ $ queryBuilder = $ this ->createQueryBuilderMock ();
246
+ $ queryBuilder
247
+ ->expects ($ this ->once ())
248
+ ->method ('select ' )
249
+ ->will ($ this ->returnSelf ())
250
+ ;
251
+ $ queryBuilder
252
+ ->expects ($ this ->once ())
253
+ ->method ('from ' )
254
+ ->will ($ this ->returnSelf ())
255
+ ;
256
+ $ queryBuilder
257
+ ->expects ($ this ->once ())
258
+ ->method ('where ' )
259
+ ->will ($ this ->returnSelf ())
260
+ ;
261
+ $ queryBuilder
262
+ ->expects ($ this ->once ())
263
+ ->method ('andWhere ' )
264
+ ->will ($ this ->returnSelf ())
265
+ ;
266
+ $ queryBuilder
267
+ ->expects ($ this ->exactly (2 ))
268
+ ->method ('orderBy ' )
269
+ ->will ($ this ->returnSelf ())
270
+ ;
271
+
272
+ $ platform = $ this ->createPlatformMock ();
273
+
204
274
$ dbal = $ this ->createConnectionMock ();
275
+ $ dbal
276
+ ->expects ($ this ->once ())
277
+ ->method ('createQueryBuilder ' )
278
+ ->willReturn ($ queryBuilder )
279
+ ;
205
280
$ dbal
206
281
->expects ($ this ->once ())
207
282
->method ('executeQuery ' )
@@ -216,6 +291,11 @@ public function testShouldReturnNullIfThereIsNoNewMessage()
216
291
->expects ($ this ->once ())
217
292
->method ('commit ' )
218
293
;
294
+ $ dbal
295
+ ->expects ($ this ->once ())
296
+ ->method ('getDatabasePlatform ' )
297
+ ->willReturn ($ platform )
298
+ ;
219
299
220
300
$ context = $ this ->createContextMock ();
221
301
$ context
@@ -250,7 +330,41 @@ public function testShouldThrowIfMessageWasNotRemoved()
250
330
->will ($ this ->returnValue (['id ' => '2134 ' ]))
251
331
;
252
332
333
+ $ queryBuilder = $ this ->createQueryBuilderMock ();
334
+ $ queryBuilder
335
+ ->expects ($ this ->once ())
336
+ ->method ('select ' )
337
+ ->will ($ this ->returnSelf ())
338
+ ;
339
+ $ queryBuilder
340
+ ->expects ($ this ->once ())
341
+ ->method ('from ' )
342
+ ->will ($ this ->returnSelf ())
343
+ ;
344
+ $ queryBuilder
345
+ ->expects ($ this ->once ())
346
+ ->method ('where ' )
347
+ ->will ($ this ->returnSelf ())
348
+ ;
349
+ $ queryBuilder
350
+ ->expects ($ this ->once ())
351
+ ->method ('andWhere ' )
352
+ ->will ($ this ->returnSelf ())
353
+ ;
354
+ $ queryBuilder
355
+ ->expects ($ this ->exactly (2 ))
356
+ ->method ('orderBy ' )
357
+ ->will ($ this ->returnSelf ())
358
+ ;
359
+
360
+ $ platform = $ this ->createPlatformMock ();
361
+
253
362
$ dbal = $ this ->createConnectionMock ();
363
+ $ dbal
364
+ ->expects ($ this ->once ())
365
+ ->method ('createQueryBuilder ' )
366
+ ->willReturn ($ queryBuilder )
367
+ ;
254
368
$ dbal
255
369
->expects ($ this ->once ())
256
370
->method ('executeQuery ' )
@@ -269,6 +383,11 @@ public function testShouldThrowIfMessageWasNotRemoved()
269
383
->expects ($ this ->once ())
270
384
->method ('rollBack ' )
271
385
;
386
+ $ dbal
387
+ ->expects ($ this ->once ())
388
+ ->method ('getDatabasePlatform ' )
389
+ ->willReturn ($ platform )
390
+ ;
272
391
273
392
$ context = $ this ->createContextMock ();
274
393
$ context
@@ -318,6 +437,22 @@ private function createContextMock()
318
437
{
319
438
return $ this ->createMock (DbalContext::class);
320
439
}
440
+
441
+ /**
442
+ * @return \PHPUnit_Framework_MockObject_MockObject|QueryBuilder
443
+ */
444
+ private function createQueryBuilderMock ()
445
+ {
446
+ return $ this ->createMock (QueryBuilder::class);
447
+ }
448
+
449
+ /**
450
+ * @return \PHPUnit_Framework_MockObject_MockObject|AbstractPlatform
451
+ */
452
+ private function createPlatformMock ()
453
+ {
454
+ return $ this ->createMock (AbstractPlatform::class);
455
+ }
321
456
}
322
457
323
458
class InvalidMessage implements PsrMessage
0 commit comments