@@ -27,16 +27,20 @@ public function testPushProperlyPushesJobOntoRedis()
27
27
return $ uuid ;
28
28
});
29
29
30
+ $ time = Carbon::now ();
31
+ Carbon::setTestNow ($ time );
32
+
30
33
$ queue = $ this ->getMockBuilder (RedisQueue::class)->onlyMethods (['getRandomId ' ])->setConstructorArgs ([$ redis = m::mock (Factory::class), 'default ' ])->getMock ();
31
34
$ queue ->expects ($ this ->once ())->method ('getRandomId ' )->willReturn ('foo ' );
32
35
$ queue ->setContainer ($ container = m::spy (Container::class));
33
36
$ 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 ]));
35
38
36
39
$ id = $ queue ->push ('foo ' , ['data ' ]);
37
40
$ this ->assertSame ('foo ' , $ id );
38
41
$ container ->shouldHaveReceived ('bound ' )->with ('events ' )->twice ();
39
42
43
+ Carbon::setTestNow ();
40
44
Str::createUuidsNormally ();
41
45
}
42
46
@@ -48,11 +52,14 @@ public function testPushProperlyPushesJobOntoRedisWithCustomPayloadHook()
48
52
return $ uuid ;
49
53
});
50
54
55
+ $ time = Carbon::now ();
56
+ Carbon::setTestNow ($ time );
57
+
51
58
$ queue = $ this ->getMockBuilder (RedisQueue::class)->onlyMethods (['getRandomId ' ])->setConstructorArgs ([$ redis = m::mock (Factory::class), 'default ' ])->getMock ();
52
59
$ queue ->expects ($ this ->once ())->method ('getRandomId ' )->willReturn ('foo ' );
53
60
$ queue ->setContainer ($ container = m::spy (Container::class));
54
61
$ 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 ]));
56
63
57
64
Queue::createPayloadUsing (function ($ connection , $ queue , $ payload ) {
58
65
return ['custom ' => 'taylor ' ];
@@ -64,6 +71,7 @@ public function testPushProperlyPushesJobOntoRedisWithCustomPayloadHook()
64
71
65
72
Queue::createPayloadUsing (null );
66
73
74
+ Carbon::setTestNow ();
67
75
Str::createUuidsNormally ();
68
76
}
69
77
@@ -75,11 +83,14 @@ public function testPushProperlyPushesJobOntoRedisWithTwoCustomPayloadHook()
75
83
return $ uuid ;
76
84
});
77
85
86
+ $ time = Carbon::now ();
87
+ Carbon::setTestNow ($ time );
88
+
78
89
$ queue = $ this ->getMockBuilder (RedisQueue::class)->onlyMethods (['getRandomId ' ])->setConstructorArgs ([$ redis = m::mock (Factory::class), 'default ' ])->getMock ();
79
90
$ queue ->expects ($ this ->once ())->method ('getRandomId ' )->willReturn ('foo ' );
80
91
$ queue ->setContainer ($ container = m::spy (Container::class));
81
92
$ 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 ]));
83
94
84
95
Queue::createPayloadUsing (function ($ connection , $ queue , $ payload ) {
85
96
return ['custom ' => 'taylor ' ];
@@ -95,6 +106,7 @@ public function testPushProperlyPushesJobOntoRedisWithTwoCustomPayloadHook()
95
106
96
107
Queue::createPayloadUsing (null );
97
108
109
+ Carbon::setTestNow ();
98
110
Str::createUuidsNormally ();
99
111
}
100
112
@@ -106,6 +118,9 @@ public function testDelayedPushProperlyPushesJobOntoRedis()
106
118
return $ uuid ;
107
119
});
108
120
121
+ $ time = Carbon::now ();
122
+ Carbon::setTestNow ($ time );
123
+
109
124
$ queue = $ this ->getMockBuilder (RedisQueue::class)->onlyMethods (['availableAt ' , 'getRandomId ' ])->setConstructorArgs ([$ redis = m::mock (Factory::class), 'default ' ])->getMock ();
110
125
$ queue ->setContainer ($ container = m::spy (Container::class));
111
126
$ queue ->expects ($ this ->once ())->method ('getRandomId ' )->willReturn ('foo ' );
@@ -115,13 +130,14 @@ public function testDelayedPushProperlyPushesJobOntoRedis()
115
130
$ redis ->shouldReceive ('zadd ' )->once ()->with (
116
131
'queues:default:delayed ' ,
117
132
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 ])
119
134
);
120
135
121
136
$ id = $ queue ->later (1 , 'foo ' , ['data ' ]);
122
137
$ this ->assertSame ('foo ' , $ id );
123
138
$ container ->shouldHaveReceived ('bound ' )->with ('events ' )->twice ();
124
139
140
+ Carbon::setTestNow ();
125
141
Str::createUuidsNormally ();
126
142
}
127
143
@@ -133,22 +149,24 @@ public function testDelayedPushWithDateTimeProperlyPushesJobOntoRedis()
133
149
return $ uuid ;
134
150
});
135
151
136
- $ date = Carbon::now ();
152
+ $ time = $ date = Carbon::now ();
153
+ Carbon::setTestNow ($ time );
137
154
$ queue = $ this ->getMockBuilder (RedisQueue::class)->onlyMethods (['availableAt ' , 'getRandomId ' ])->setConstructorArgs ([$ redis = m::mock (Factory::class), 'default ' ])->getMock ();
138
155
$ queue ->setContainer ($ container = m::spy (Container::class));
139
156
$ 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 );
141
158
142
159
$ redis ->shouldReceive ('connection ' )->once ()->andReturn ($ redis );
143
160
$ redis ->shouldReceive ('zadd ' )->once ()->with (
144
161
'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 ])
147
164
);
148
165
149
- $ queue ->later ($ date , 'foo ' , ['data ' ]);
166
+ $ queue ->later ($ date-> addSeconds ( 5 ) , 'foo ' , ['data ' ]);
150
167
$ container ->shouldHaveReceived ('bound ' )->with ('events ' )->twice ();
151
168
169
+ Carbon::setTestNow ();
152
170
Str::createUuidsNormally ();
153
171
}
154
172
}
0 commit comments