5
5
namespace MongoDB \Laravel \Tests ;
6
6
7
7
use Carbon \Carbon ;
8
+ use Exception ;
8
9
use Illuminate \Support \Facades \Config ;
9
10
use Illuminate \Support \Facades \Queue ;
10
11
use Illuminate \Support \Str ;
11
12
use Mockery ;
13
+ use MongoDB \BSON \UTCDateTime ;
12
14
use MongoDB \Laravel \Queue \Failed \MongoFailedJobProvider ;
13
15
use MongoDB \Laravel \Queue \MongoJob ;
14
16
use MongoDB \Laravel \Queue \MongoQueue ;
@@ -30,10 +32,7 @@ public function setUp(): void
30
32
public function testQueueJobLifeCycle (): void
31
33
{
32
34
$ uuid = Str::uuid ();
33
-
34
- Str::createUuidsUsing (function () use ($ uuid ) {
35
- return $ uuid ;
36
- });
35
+ Str::createUuidsUsing (fn () => $ uuid );
37
36
38
37
$ id = Queue::push ('test ' , ['action ' => 'QueueJobLifeCycle ' ], 'test ' );
39
38
$ this ->assertNotNull ($ id );
@@ -185,4 +184,19 @@ public function testQueueDeleteAndRelease(): void
185
184
186
185
$ mock ->deleteAndRelease ($ queue , $ job , $ delay );
187
186
}
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
+ }
188
202
}
0 commit comments