@@ -171,4 +171,48 @@ public function it_returns_the_latest_log_date_when_any_of_the_log_entries_are_l
171
171
172
172
$ this ->assertEquals ('2024-11-27 14:00:20 ' , $ job ->lastTimeSomethingHasHappenedWithIt ()->format ('Y-m-d H:i:s ' ));
173
173
}
174
+
175
+ /** @test */
176
+ public function the_actives_scope_returns_the_records_where_neither_completed_at_nor_failed_at_are_set ()
177
+ {
178
+ JobExecution::ofJobClass (SampleTrackableJob::class)->delete ();
179
+
180
+ $ this ->createSampleJobExecution ();
181
+ $ this ->createSampleJobExecution ();
182
+ $ this ->createSampleJobExecution ();
183
+ $ this ->createSampleJobExecution ();
184
+ $ this ->createSampleJobExecution (['failed_at ' => Carbon::now ()]);
185
+ $ this ->createSampleJobExecution (['completed_at ' => Carbon::now ()]);
186
+ $ this ->createSampleJobExecution (['completed_at ' => Carbon::now (), 'failed_at ' => Carbon::now ()]); // stupid, yeah
187
+
188
+ $ this ->assertCount (4 , JobExecution::actives ()->get ());
189
+ }
190
+
191
+ /** @test */
192
+ public function the_ended_scope_returns_the_records_where_either_completed_at_or_failed_at_are_set ()
193
+ {
194
+ JobExecution::ofJobClass (SampleTrackableJob::class)->delete ();
195
+
196
+ $ this ->createSampleJobExecution ();
197
+ $ this ->createSampleJobExecution ();
198
+ $ this ->createSampleJobExecution (['failed_at ' => Carbon::now ()]);
199
+ $ this ->createSampleJobExecution (['completed_at ' => Carbon::now ()]);
200
+ $ this ->createSampleJobExecution (['completed_at ' => Carbon::now (), 'failed_at ' => Carbon::now ()]);
201
+
202
+ $ this ->assertCount (3 , JobExecution::ended ()->get ());
203
+ }
204
+
205
+ private function createSampleJobExecution (array $ attributes = []): JobExecution
206
+ {
207
+ $ data = array_merge (
208
+ [
209
+ 'job_class ' => SampleTrackableJob::class,
210
+ 'tracking_id ' => Str::ulid ()->toBase58 (),
211
+ 'queued_at ' => Carbon::now (),
212
+ ],
213
+ $ attributes ,
214
+ );
215
+
216
+ return JobExecution::create ($ data );
217
+ }
174
218
}
0 commit comments