@@ -27,16 +27,20 @@ public function testPushProperlyPushesJobOntoRedis()
2727 return $ uuid ;
2828 });
2929
30+ $ time = Carbon::now ();
31+ Carbon::setTestNow ($ time );
32+
3033 $ queue = $ this ->getMockBuilder (RedisQueue::class)->onlyMethods (['getRandomId ' ])->setConstructorArgs ([$ redis = m::mock (Factory::class), 'default ' ])->getMock ();
3134 $ queue ->expects ($ this ->once ())->method ('getRandomId ' )->willReturn ('foo ' );
3235 $ queue ->setContainer ($ container = m::spy (Container::class));
3336 $ redis ->shouldReceive ('connection ' )->once ()->andReturn ($ redis );
34- $ redis ->shouldReceive ('eval ' )->once ()->with (LuaScripts::push (), 2 , 'queues:default ' , 'queues:default:notify ' , json_encode (['uuid ' => $ uuid , 'displayName ' => 'foo ' , 'job ' => 'foo ' , 'maxTries ' => null , 'maxExceptions ' => null , 'failOnTimeout ' => false , 'backoff ' => null , 'timeout ' => null , 'data ' => ['data ' ], 'id ' => 'foo ' , 'attempts ' => 0 ]));
37+ $ redis ->shouldReceive ('eval ' )->once ()->with (LuaScripts::push (), 2 , 'queues:default ' , 'queues:default:notify ' , json_encode (['uuid ' => $ uuid , 'displayName ' => 'foo ' , 'job ' => 'foo ' , 'maxTries ' => null , 'maxExceptions ' => null , 'failOnTimeout ' => false , 'backoff ' => null , 'timeout ' => null , 'data ' => ['data ' ], 'createdAt ' => $ time -> getTimestamp (), ' id ' => 'foo ' , 'attempts ' => 0 , ' delay ' => null ]));
3538
3639 $ id = $ queue ->push ('foo ' , ['data ' ]);
3740 $ this ->assertSame ('foo ' , $ id );
3841 $ container ->shouldHaveReceived ('bound ' )->with ('events ' )->twice ();
3942
43+ Carbon::setTestNow ();
4044 Str::createUuidsNormally ();
4145 }
4246
@@ -48,11 +52,14 @@ public function testPushProperlyPushesJobOntoRedisWithCustomPayloadHook()
4852 return $ uuid ;
4953 });
5054
55+ $ time = Carbon::now ();
56+ Carbon::setTestNow ($ time );
57+
5158 $ queue = $ this ->getMockBuilder (RedisQueue::class)->onlyMethods (['getRandomId ' ])->setConstructorArgs ([$ redis = m::mock (Factory::class), 'default ' ])->getMock ();
5259 $ queue ->expects ($ this ->once ())->method ('getRandomId ' )->willReturn ('foo ' );
5360 $ queue ->setContainer ($ container = m::spy (Container::class));
5461 $ redis ->shouldReceive ('connection ' )->once ()->andReturn ($ redis );
55- $ redis ->shouldReceive ('eval ' )->once ()->with (LuaScripts::push (), 2 , 'queues:default ' , 'queues:default:notify ' , json_encode (['uuid ' => $ uuid , 'displayName ' => 'foo ' , 'job ' => 'foo ' , 'maxTries ' => null , 'maxExceptions ' => null , 'failOnTimeout ' => false , 'backoff ' => null , 'timeout ' => null , 'data ' => ['data ' ], 'custom ' => 'taylor ' , 'id ' => 'foo ' , 'attempts ' => 0 ]));
62+ $ redis ->shouldReceive ('eval ' )->once ()->with (LuaScripts::push (), 2 , 'queues:default ' , 'queues:default:notify ' , json_encode (['uuid ' => $ uuid , 'displayName ' => 'foo ' , 'job ' => 'foo ' , 'maxTries ' => null , 'maxExceptions ' => null , 'failOnTimeout ' => false , 'backoff ' => null , 'timeout ' => null , 'data ' => ['data ' ], 'createdAt ' => $ time -> getTimestamp (), ' custom ' => 'taylor ' , 'id ' => 'foo ' , 'attempts ' => 0 , ' delay ' => null ]));
5663
5764 Queue::createPayloadUsing (function ($ connection , $ queue , $ payload ) {
5865 return ['custom ' => 'taylor ' ];
@@ -64,6 +71,7 @@ public function testPushProperlyPushesJobOntoRedisWithCustomPayloadHook()
6471
6572 Queue::createPayloadUsing (null );
6673
74+ Carbon::setTestNow ();
6775 Str::createUuidsNormally ();
6876 }
6977
@@ -75,11 +83,14 @@ public function testPushProperlyPushesJobOntoRedisWithTwoCustomPayloadHook()
7583 return $ uuid ;
7684 });
7785
86+ $ time = Carbon::now ();
87+ Carbon::setTestNow ($ time );
88+
7889 $ queue = $ this ->getMockBuilder (RedisQueue::class)->onlyMethods (['getRandomId ' ])->setConstructorArgs ([$ redis = m::mock (Factory::class), 'default ' ])->getMock ();
7990 $ queue ->expects ($ this ->once ())->method ('getRandomId ' )->willReturn ('foo ' );
8091 $ queue ->setContainer ($ container = m::spy (Container::class));
8192 $ redis ->shouldReceive ('connection ' )->once ()->andReturn ($ redis );
82- $ redis ->shouldReceive ('eval ' )->once ()->with (LuaScripts::push (), 2 , 'queues:default ' , 'queues:default:notify ' , json_encode (['uuid ' => $ uuid , 'displayName ' => 'foo ' , 'job ' => 'foo ' , 'maxTries ' => null , 'maxExceptions ' => null , 'failOnTimeout ' => false , 'backoff ' => null , 'timeout ' => null , 'data ' => ['data ' ], 'custom ' => 'taylor ' , 'bar ' => 'foo ' , 'id ' => 'foo ' , 'attempts ' => 0 ]));
93+ $ redis ->shouldReceive ('eval ' )->once ()->with (LuaScripts::push (), 2 , 'queues:default ' , 'queues:default:notify ' , json_encode (['uuid ' => $ uuid , 'displayName ' => 'foo ' , 'job ' => 'foo ' , 'maxTries ' => null , 'maxExceptions ' => null , 'failOnTimeout ' => false , 'backoff ' => null , 'timeout ' => null , 'data ' => ['data ' ], 'createdAt ' => $ time -> getTimestamp (), ' custom ' => 'taylor ' , 'bar ' => 'foo ' , 'id ' => 'foo ' , 'attempts ' => 0 , ' delay ' => null ]));
8394
8495 Queue::createPayloadUsing (function ($ connection , $ queue , $ payload ) {
8596 return ['custom ' => 'taylor ' ];
@@ -95,6 +106,7 @@ public function testPushProperlyPushesJobOntoRedisWithTwoCustomPayloadHook()
95106
96107 Queue::createPayloadUsing (null );
97108
109+ Carbon::setTestNow ();
98110 Str::createUuidsNormally ();
99111 }
100112
@@ -106,6 +118,9 @@ public function testDelayedPushProperlyPushesJobOntoRedis()
106118 return $ uuid ;
107119 });
108120
121+ $ time = Carbon::now ();
122+ Carbon::setTestNow ($ time );
123+
109124 $ queue = $ this ->getMockBuilder (RedisQueue::class)->onlyMethods (['availableAt ' , 'getRandomId ' ])->setConstructorArgs ([$ redis = m::mock (Factory::class), 'default ' ])->getMock ();
110125 $ queue ->setContainer ($ container = m::spy (Container::class));
111126 $ queue ->expects ($ this ->once ())->method ('getRandomId ' )->willReturn ('foo ' );
@@ -115,13 +130,14 @@ public function testDelayedPushProperlyPushesJobOntoRedis()
115130 $ redis ->shouldReceive ('zadd ' )->once ()->with (
116131 'queues:default:delayed ' ,
117132 2 ,
118- json_encode (['uuid ' => $ uuid , 'displayName ' => 'foo ' , 'job ' => 'foo ' , 'maxTries ' => null , 'maxExceptions ' => null , 'failOnTimeout ' => false , 'backoff ' => null , 'timeout ' => null , 'data ' => ['data ' ], 'id ' => 'foo ' , 'attempts ' => 0 ])
133+ json_encode (['uuid ' => $ uuid , 'displayName ' => 'foo ' , 'job ' => 'foo ' , 'maxTries ' => null , 'maxExceptions ' => null , 'failOnTimeout ' => false , 'backoff ' => null , 'timeout ' => null , 'data ' => ['data ' ], 'createdAt ' => $ time -> getTimestamp (), ' id ' => 'foo ' , 'attempts ' => 0 , ' delay ' => 1 ])
119134 );
120135
121136 $ id = $ queue ->later (1 , 'foo ' , ['data ' ]);
122137 $ this ->assertSame ('foo ' , $ id );
123138 $ container ->shouldHaveReceived ('bound ' )->with ('events ' )->twice ();
124139
140+ Carbon::setTestNow ();
125141 Str::createUuidsNormally ();
126142 }
127143
@@ -133,22 +149,24 @@ public function testDelayedPushWithDateTimeProperlyPushesJobOntoRedis()
133149 return $ uuid ;
134150 });
135151
136- $ date = Carbon::now ();
152+ $ time = $ date = Carbon::now ();
153+ Carbon::setTestNow ($ time );
137154 $ queue = $ this ->getMockBuilder (RedisQueue::class)->onlyMethods (['availableAt ' , 'getRandomId ' ])->setConstructorArgs ([$ redis = m::mock (Factory::class), 'default ' ])->getMock ();
138155 $ queue ->setContainer ($ container = m::spy (Container::class));
139156 $ queue ->expects ($ this ->once ())->method ('getRandomId ' )->willReturn ('foo ' );
140- $ queue ->expects ($ this ->once ())->method ('availableAt ' )->with ($ date )->willReturn (2 );
157+ $ queue ->expects ($ this ->once ())->method ('availableAt ' )->with ($ date )->willReturn (5 );
141158
142159 $ redis ->shouldReceive ('connection ' )->once ()->andReturn ($ redis );
143160 $ redis ->shouldReceive ('zadd ' )->once ()->with (
144161 'queues:default:delayed ' ,
145- 2 ,
146- json_encode (['uuid ' => $ uuid , 'displayName ' => 'foo ' , 'job ' => 'foo ' , 'maxTries ' => null , 'maxExceptions ' => null , 'failOnTimeout ' => false , 'backoff ' => null , 'timeout ' => null , 'data ' => ['data ' ], 'id ' => 'foo ' , 'attempts ' => 0 ])
162+ 5 ,
163+ json_encode (['uuid ' => $ uuid , 'displayName ' => 'foo ' , 'job ' => 'foo ' , 'maxTries ' => null , 'maxExceptions ' => null , 'failOnTimeout ' => false , 'backoff ' => null , 'timeout ' => null , 'data ' => ['data ' ], 'createdAt ' => $ time -> getTimestamp (), ' id ' => 'foo ' , 'attempts ' => 0 , ' delay ' => 5 ])
147164 );
148165
149- $ queue ->later ($ date , 'foo ' , ['data ' ]);
166+ $ queue ->later ($ date-> addSeconds ( 5 ) , 'foo ' , ['data ' ]);
150167 $ container ->shouldHaveReceived ('bound ' )->with ('events ' )->twice ();
151168
169+ Carbon::setTestNow ();
152170 Str::createUuidsNormally ();
153171 }
154172}
0 commit comments