55namespace MongoDB \Laravel \Tests ;
66
77use Carbon \Carbon ;
8+ use Exception ;
89use Illuminate \Support \Facades \Config ;
910use Illuminate \Support \Facades \Queue ;
1011use Illuminate \Support \Str ;
1112use Mockery ;
13+ use MongoDB \BSON \UTCDateTime ;
1214use MongoDB \Laravel \Queue \Failed \MongoFailedJobProvider ;
1315use MongoDB \Laravel \Queue \MongoJob ;
1416use MongoDB \Laravel \Queue \MongoQueue ;
@@ -30,10 +32,7 @@ public function setUp(): void
3032 public function testQueueJobLifeCycle (): void
3133 {
3234 $ uuid = Str::uuid ();
33-
34- Str::createUuidsUsing (function () use ($ uuid ) {
35- return $ uuid ;
36- });
35+ Str::createUuidsUsing (fn () => $ uuid );
3736
3837 $ id = Queue::push ('test ' , ['action ' => 'QueueJobLifeCycle ' ], 'test ' );
3938 $ this ->assertNotNull ($ id );
@@ -185,4 +184,19 @@ public function testQueueDeleteAndRelease(): void
185184
186185 $ mock ->deleteAndRelease ($ queue , $ job , $ delay );
187186 }
187+
188+ public function testFailedJobLogging ()
189+ {
190+ Carbon::setTestNow ('2019-01-01 00:00:00 ' );
191+ $ provider = app ('queue.failer ' );
192+ $ provider ->log ('test_connection ' , 'test_queue ' , 'test_payload ' , new Exception ('test_exception ' ));
193+
194+ $ failedJob = Queue::getDatabase ()->table (Config::get ('queue.failed.table ' ))->first ();
195+
196+ $ this ->assertSame ('test_connection ' , $ failedJob ['connection ' ]);
197+ $ this ->assertSame ('test_queue ' , $ failedJob ['queue ' ]);
198+ $ this ->assertSame ('test_payload ' , $ failedJob ['payload ' ]);
199+ $ this ->assertEquals (new UTCDateTime (Carbon::now ()), $ failedJob ['failed_at ' ]);
200+ $ this ->assertStringStartsWith ('Exception: test_exception in ' , $ failedJob ['exception ' ]);
201+ }
188202}
0 commit comments