@@ -258,14 +258,12 @@ public function testShouldSendMessageToRouter()
258
258
$ producer
259
259
->expects ($ this ->once ())
260
260
->method ('send ' )
261
- ->with ($ this ->identicalTo ($ topic ), $ this ->identicalTo ($ transportMessage ))
262
- ;
263
- $ context = $ this ->createContextMock ();
264
- $ context
265
- ->expects ($ this ->once ())
266
- ->method ('createTopic ' )
267
- ->willReturn ($ topic )
261
+ ->willReturnCallback (function (PsrTopic $ topic , PsrMessage $ message ) use ($ transportMessage ) {
262
+ $ this ->assertSame ($ this ->getRouterTransportName (), $ topic ->getTopicName ());
263
+ $ this ->assertSame ($ transportMessage , $ message );
264
+ })
268
265
;
266
+ $ context = $ this ->createContextStub ();
269
267
$ context
270
268
->expects ($ this ->once ())
271
269
->method ('createProducer ' )
@@ -291,26 +289,19 @@ public function testShouldSendMessageToRouter()
291
289
292
290
public function testShouldNotInitDeliveryDelayOnSendMessageToRouter ()
293
291
{
294
- $ topic = $ this ->createTopic ('' );
295
292
$ transportMessage = $ this ->createMessage ();
296
293
297
294
$ producer = $ this ->createProducerMock ();
298
295
$ producer
299
296
->expects ($ this ->once ())
300
297
->method ('send ' )
301
- ->with ($ this ->identicalTo ($ topic ), $ this ->identicalTo ($ transportMessage ))
302
298
;
303
299
$ producer
304
300
->expects ($ this ->never ())
305
301
->method ('setDeliveryDelay ' )
306
302
;
307
303
308
- $ context = $ this ->createContextMock ();
309
- $ context
310
- ->expects ($ this ->once ())
311
- ->method ('createTopic ' )
312
- ->willReturn ($ topic )
313
- ;
304
+ $ context = $ this ->createContextStub ();
314
305
$ context
315
306
->expects ($ this ->once ())
316
307
->method ('createProducer ' )
@@ -337,26 +328,19 @@ public function testShouldNotInitDeliveryDelayOnSendMessageToRouter()
337
328
338
329
public function testShouldNotInitTimeToLiveOnSendMessageToRouter ()
339
330
{
340
- $ topic = $ this ->createTopic ('' );
341
331
$ transportMessage = $ this ->createMessage ();
342
332
343
333
$ producer = $ this ->createProducerMock ();
344
334
$ producer
345
335
->expects ($ this ->once ())
346
336
->method ('send ' )
347
- ->with ($ this ->identicalTo ($ topic ), $ this ->identicalTo ($ transportMessage ))
348
337
;
349
338
$ producer
350
339
->expects ($ this ->never ())
351
340
->method ('setTimeToLive ' )
352
341
;
353
342
354
- $ context = $ this ->createContextMock ();
355
- $ context
356
- ->expects ($ this ->once ())
357
- ->method ('createTopic ' )
358
- ->willReturn ($ topic )
359
- ;
343
+ $ context = $ this ->createContextStub ();
360
344
$ context
361
345
->expects ($ this ->once ())
362
346
->method ('createProducer ' )
@@ -383,26 +367,19 @@ public function testShouldNotInitTimeToLiveOnSendMessageToRouter()
383
367
384
368
public function testShouldNotInitPriorityOnSendMessageToRouter ()
385
369
{
386
- $ topic = $ this ->createTopic ('' );
387
370
$ transportMessage = $ this ->createMessage ();
388
371
389
372
$ producer = $ this ->createProducerMock ();
390
373
$ producer
391
374
->expects ($ this ->once ())
392
375
->method ('send ' )
393
- ->with ($ this ->identicalTo ($ topic ), $ this ->identicalTo ($ transportMessage ))
394
376
;
395
377
$ producer
396
378
->expects ($ this ->never ())
397
379
->method ('setPriority ' )
398
380
;
399
381
400
- $ context = $ this ->createContextMock ();
401
- $ context
402
- ->expects ($ this ->once ())
403
- ->method ('createTopic ' )
404
- ->willReturn ($ topic )
405
- ;
382
+ $ context = $ this ->createContextStub ();
406
383
$ context
407
384
->expects ($ this ->once ())
408
385
->method ('createProducer ' )
@@ -1104,6 +1081,32 @@ abstract protected function createTopic(string $name): PsrTopic;
1104
1081
1105
1082
abstract protected function createMessage (): PsrMessage ;
1106
1083
1084
+ /**
1085
+ * @return \PHPUnit_Framework_MockObject_MockObject
1086
+ */
1087
+ protected function createContextStub (): PsrContext
1088
+ {
1089
+ $ context = $ this ->createContextMock ();
1090
+
1091
+ $ context
1092
+ ->expects ($ this ->any ())
1093
+ ->method ('createQueue ' )
1094
+ ->willReturnCallback (function (string $ name ) {
1095
+ return $ this ->createQueue ($ name );
1096
+ })
1097
+ ;
1098
+
1099
+ $ context
1100
+ ->expects ($ this ->any ())
1101
+ ->method ('createTopic ' )
1102
+ ->willReturnCallback (function (string $ name ) {
1103
+ return $ this ->createTopic ($ name );
1104
+ })
1105
+ ;
1106
+
1107
+ return $ context ;
1108
+ }
1109
+
1107
1110
protected function assertTransportMessage (PsrMessage $ transportMessage ): void
1108
1111
{
1109
1112
$ this ->assertSame ('body ' , $ transportMessage ->getBody ());
@@ -1165,6 +1168,11 @@ protected function getCustomQueueTransportName(): string
1165
1168
return 'aprefix.custom ' ;
1166
1169
}
1167
1170
1171
+ protected function getRouterTransportName (): string
1172
+ {
1173
+ return 'aprefix.default ' ;
1174
+ }
1175
+
1168
1176
protected function getPrefixAppFooQueueTransportName (): string
1169
1177
{
1170
1178
return 'aprefix.anappname.afooqueue ' ;
0 commit comments