@@ -85,6 +85,23 @@ public function testQueueIsSetByGetConnection()
85
85
$ d ->dispatch ('some.event ' , ['foo ' , 'bar ' ]);
86
86
}
87
87
88
+ public function testDelayIsSetByWithDelay ()
89
+ {
90
+ $ d = new Dispatcher ;
91
+ $ queue = m::mock (Queue::class);
92
+
93
+ $ queue ->shouldReceive ('connection ' )->once ()->with (null )->andReturnSelf ();
94
+
95
+ $ queue ->shouldReceive ('laterOn ' )->once ()->with (null , 20 , m::type (CallQueuedListener::class));
96
+
97
+ $ d ->setQueueResolver (function () use ($ queue ) {
98
+ return $ queue ;
99
+ });
100
+
101
+ $ d ->listen ('some.event ' , TestDispatcherGetDelay::class.'@handle ' );
102
+ $ d ->dispatch ('some.event ' , ['foo ' , 'bar ' ]);
103
+ }
104
+
88
105
public function testQueueIsSetByGetQueueDynamically ()
89
106
{
90
107
$ d = new Dispatcher ;
@@ -127,6 +144,23 @@ public function testQueueIsSetByGetConnectionDynamically()
127
144
]);
128
145
}
129
146
147
+ public function testDelayIsSetByWithDelayDynamically ()
148
+ {
149
+ $ d = new Dispatcher ;
150
+ $ queue = m::mock (Queue::class);
151
+
152
+ $ queue ->shouldReceive ('connection ' )->once ()->with (null )->andReturnSelf ();
153
+
154
+ $ queue ->shouldReceive ('laterOn ' )->once ()->with (null , 60 , m::type (CallQueuedListener::class));
155
+
156
+ $ d ->setQueueResolver (function () use ($ queue ) {
157
+ return $ queue ;
158
+ });
159
+
160
+ $ d ->listen ('some.event ' , TestDispatcherGetDelayDynamically::class.'@handle ' );
161
+ $ d ->dispatch ('some.event ' , [['useHighDelay ' => true ], 'bar ' ]);
162
+ }
163
+
130
164
public function testQueuePropagateRetryUntilAndMaxExceptions ()
131
165
{
132
166
$ d = new Dispatcher ;
@@ -219,6 +253,21 @@ public function viaConnection()
219
253
}
220
254
}
221
255
256
+ class TestDispatcherGetDelay implements ShouldQueue
257
+ {
258
+ public $ delay = 10 ;
259
+
260
+ public function handle ()
261
+ {
262
+ //
263
+ }
264
+
265
+ public function withDelay ()
266
+ {
267
+ return 20 ;
268
+ }
269
+ }
270
+
222
271
class TestDispatcherOptions implements ShouldQueue
223
272
{
224
273
public $ maxExceptions = 1 ;
@@ -299,3 +348,22 @@ public function viaQueue($event)
299
348
return 'p99 ' ;
300
349
}
301
350
}
351
+
352
+ class TestDispatcherGetDelayDynamically implements ShouldQueue
353
+ {
354
+ public $ delay = 10 ;
355
+
356
+ public function handle ()
357
+ {
358
+ //
359
+ }
360
+
361
+ public function withDelay ($ event )
362
+ {
363
+ if ($ event ['useHighDelay ' ]) {
364
+ return 60 ;
365
+ }
366
+
367
+ return 20 ;
368
+ }
369
+ }
0 commit comments