55use Firebase \JWT \ExpiredException ;
66use Google \Cloud \Tasks \V2 \RetryConfig ;
77use Google \Protobuf \Duration ;
8+ use Illuminate \Database \Eloquent \Model ;
89use Illuminate \Queue \Events \JobExceptionOccurred ;
910use Illuminate \Queue \Events \JobFailed ;
1011use Illuminate \Queue \Events \JobProcessed ;
1112use Illuminate \Queue \Events \JobProcessing ;
13+ use Illuminate \Support \Facades \DB ;
1214use Illuminate \Support \Facades \Event ;
1315use Illuminate \Support \Facades \Log ;
16+ use Illuminate \Support \Facades \Queue ;
1417use Stackkit \LaravelGoogleCloudTasksQueue \CloudTasksApi ;
1518use Stackkit \LaravelGoogleCloudTasksQueue \CloudTasksException ;
1619use Stackkit \LaravelGoogleCloudTasksQueue \CloudTasksJob ;
1720use Stackkit \LaravelGoogleCloudTasksQueue \LogFake ;
1821use Stackkit \LaravelGoogleCloudTasksQueue \OpenIdVerificator ;
22+ use Stackkit \LaravelGoogleCloudTasksQueue \StackkitCloudTask ;
1923use Tests \Support \FailingJob ;
2024use Tests \Support \SimpleJob ;
2125use UnexpectedValueException ;
@@ -107,14 +111,9 @@ public function it_can_run_a_task()
107111 Event::fake ([JobProcessing::class, JobProcessed::class]);
108112
109113 // Act
110- $ this ->dispatch (new SimpleJob ())->run ();
114+ $ this ->dispatch (new SimpleJob ())->runWithoutExceptionHandler ();
111115
112116 // Assert
113- Event::assertDispatchedTimes (JobProcessing::class, 1 );
114- Event::assertDispatchedTimes (JobProcessed::class, 1 );
115- Event::assertDispatched (JobProcessed::class, function (JobProcessed $ event ) {
116- return $ event ->job ->resolveName () === 'Tests \\Support \\SimpleJob ' ;
117- });
118117 Log::assertLogged ('SimpleJob:success ' );
119118 }
120119
@@ -243,16 +242,17 @@ public function test_max_attempts_in_combination_with_retry_until()
243242 ->setMaxRetryDuration (new Duration (['seconds ' => 3 ]))
244243 );
245244 CloudTasksApi::partialMock ()->shouldReceive ('getRetryUntilTimestamp ' )->andReturn (time () + 1 )->byDefault ();
246- Event:: fake ([JobExceptionOccurred::class, JobFailed::class]);
245+
247246 $ job = $ this ->dispatch (new FailingJob ());
248247
249248 // Act & Assert
250249 $ job ->run ();
251250 $ job ->run ();
252251
253252 # After 2 attempts both Laravel versions should report the same: 2 errors and 0 failures.
254- Event::assertDispatchedTimes (JobExceptionOccurred::class, 2 );
255- Event::assertNotDispatched (JobFailed::class);
253+ $ task = StackkitCloudTask::whereTaskUuid ($ job ->payload ['uuid ' ])->firstOrFail ();
254+ $ this ->assertEquals (2 , $ task ->getNumberOfAttempts ());
255+ $ this ->assertEquals ('error ' , $ task ->status );
256256
257257 $ job ->run ();
258258
@@ -261,15 +261,15 @@ public function test_max_attempts_in_combination_with_retry_until()
261261 # Laravel 8+: don't fail because retryUntil has not yet passed.
262262
263263 if (version_compare (app ()->version (), '8.0.0 ' , '< ' )) {
264- Event:: assertDispatched (JobFailed::class );
264+ $ this -> assertEquals ( ' failed ' , $ task -> fresh ()-> status );
265265 return ;
266266 } else {
267- Event:: assertNotDispatched (JobFailed::class );
267+ $ this -> assertEquals ( ' error ' , $ task -> fresh ()-> status );
268268 }
269269
270270 CloudTasksApi::shouldReceive ('getRetryUntilTimestamp ' )->andReturn (time () - 1 );
271271 $ job ->run ();
272272
273- Event:: assertDispatched (JobFailed::class );
273+ $ this -> assertEquals ( ' failed ' , $ task -> fresh ()-> status );
274274 }
275275}
0 commit comments