@@ -19,10 +19,11 @@ protected function tearDown(): void
19
19
m::close ();
20
20
}
21
21
22
- public function testPushProperlyPushesJobOntoDatabase ()
22
+ /**
23
+ * @dataProvider pushJobsDataProvider
24
+ */
25
+ public function testPushProperlyPushesJobOntoDatabase ($ uuid , $ job , $ displayNameStartsWith , $ jobStartsWith )
23
26
{
24
- $ uuid = Str::uuid ();
25
-
26
27
Str::createUuidsUsing (function () use ($ uuid ) {
27
28
return $ uuid ;
28
29
});
@@ -31,21 +32,36 @@ public function testPushProperlyPushesJobOntoDatabase()
31
32
$ queue ->expects ($ this ->any ())->method ('currentTime ' )->willReturn ('time ' );
32
33
$ queue ->setContainer ($ container = m::spy (Container::class));
33
34
$ database ->shouldReceive ('table ' )->with ('table ' )->andReturn ($ query = m::mock (stdClass::class));
34
- $ query ->shouldReceive ('insertGetId ' )->once ()->andReturnUsing (function ($ array ) use ($ uuid ) {
35
+ $ query ->shouldReceive ('insertGetId ' )->once ()->andReturnUsing (function ($ array ) use ($ uuid , $ displayNameStartsWith , $ jobStartsWith ) {
36
+ $ payload = json_decode ($ array ['payload ' ], true );
37
+ $ this ->assertSame ($ uuid , $ payload ['uuid ' ]);
38
+ $ this ->assertStringContainsString ($ displayNameStartsWith , $ payload ['displayName ' ]);
39
+ $ this ->assertStringContainsString ($ jobStartsWith , $ payload ['job ' ]);
40
+
35
41
$ this ->assertSame ('default ' , $ array ['queue ' ]);
36
- $ this ->assertSame (json_encode (['uuid ' => $ uuid , 'displayName ' => 'foo ' , 'job ' => 'foo ' , 'maxTries ' => null , 'maxExceptions ' => null , 'failOnTimeout ' => false , 'backoff ' => null , 'timeout ' => null , 'data ' => ['data ' ]]), $ array ['payload ' ]);
37
42
$ this ->assertEquals (0 , $ array ['attempts ' ]);
38
43
$ this ->assertNull ($ array ['reserved_at ' ]);
39
44
$ this ->assertIsInt ($ array ['available_at ' ]);
40
45
});
41
46
42
- $ queue ->push (' foo ' , ['data ' ]);
47
+ $ queue ->push ($ job , ['data ' ]);
43
48
44
49
$ container ->shouldHaveReceived ('bound ' )->with ('events ' )->once ();
45
50
46
51
Str::createUuidsNormally ();
47
52
}
48
53
54
+ public static function pushJobsDataProvider ()
55
+ {
56
+ $ uuid = Str::uuid ()->toString ();
57
+
58
+ return [
59
+ [$ uuid , new MyTestJob , 'MyTestJob ' , 'CallQueuedHandler ' ],
60
+ [$ uuid , fn () => 0 , 'Closure ' , 'CallQueuedHandler ' ],
61
+ [$ uuid , 'foo ' , 'foo ' , 'foo ' ],
62
+ ];
63
+ }
64
+
49
65
public function testDelayedPushProperlyPushesJobOntoDatabase ()
50
66
{
51
67
$ uuid = Str::uuid ();
@@ -153,3 +169,11 @@ public function testBuildDatabaseRecordWithPayloadAtTheEnd()
153
169
$ this ->assertArrayHasKey ('payload ' , array_slice ($ record , -1 , 1 , true ));
154
170
}
155
171
}
172
+
173
+ class MyTestJob
174
+ {
175
+ public function handle ()
176
+ {
177
+ // ...
178
+ }
179
+ }
0 commit comments