@@ -85,6 +85,23 @@ public function testQueueIsSetByGetConnection()
8585 $ d ->dispatch ('some.event ' , ['foo ' , 'bar ' ]);
8686 }
8787
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+
88105 public function testQueueIsSetByGetQueueDynamically ()
89106 {
90107 $ d = new Dispatcher ;
@@ -127,6 +144,23 @@ public function testQueueIsSetByGetConnectionDynamically()
127144 ]);
128145 }
129146
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+
130164 public function testQueuePropagateRetryUntilAndMaxExceptions ()
131165 {
132166 $ d = new Dispatcher ;
@@ -219,6 +253,21 @@ public function viaConnection()
219253 }
220254}
221255
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+
222271class TestDispatcherOptions implements ShouldQueue
223272{
224273 public $ maxExceptions = 1 ;
@@ -299,3 +348,22 @@ public function viaQueue($event)
299348 return 'p99 ' ;
300349 }
301350}
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