File tree Expand file tree Collapse file tree 2 files changed +66
-0
lines changed Expand file tree Collapse file tree 2 files changed +66
-0
lines changed Original file line number Diff line number Diff line change 2525use Tests \Support \JobThatWillBeReleased ;
2626use Illuminate \Queue \Events \JobProcessed ;
2727use Illuminate \Queue \Events \JobProcessing ;
28+ use Tests \Support \SimpleJobWithDelayProperty ;
2829use Tests \Support \FailingJobWithExponentialBackoff ;
2930use Illuminate \Queue \Events \JobReleasedAfterException ;
3031use Stackkit \LaravelGoogleCloudTasksQueue \IncomingTask ;
@@ -613,4 +614,39 @@ public function task_has_configured_dispatch_deadline(): void
613614 return $ task ->getDispatchDeadline ()->getSeconds () === 1800 ;
614615 });
615616 }
617+
618+ #[Test]
619+ public function it_will_set_the_scheduled_time_when_job_has_delay_property (): void
620+ {
621+ // Arrange
622+ CloudTasksApi::fake ();
623+ Carbon::setTestNow (now ()->addDay ());
624+
625+ // Act
626+ $ this ->dispatch (Bus::batch ([
627+ new SimpleJobWithDelayProperty (500 ),
628+ ]));
629+
630+ // Assert
631+ CloudTasksApi::assertTaskCreated (function (Task $ task ): bool {
632+ return $ task ->getScheduleTime ()->getSeconds () === now ()->addSeconds (500 )->timestamp ;
633+ });
634+ }
635+
636+ #[Test]
637+ public function it_will_not_set_scheduled_time_when_job_delay_property_is_null (): void
638+ {
639+ // Arrange
640+ CloudTasksApi::fake ();
641+
642+ // Act
643+ $ this ->dispatch (Bus::batch ([
644+ new SimpleJobWithDelayProperty (null ),
645+ ]));
646+
647+ // Assert
648+ CloudTasksApi::assertTaskCreated (function (Task $ task ): bool {
649+ return $ task ->getScheduleTime () === null ;
650+ });
651+ }
616652}
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Tests \Support ;
6+
7+ class SimpleJobWithDelayProperty extends BaseJob
8+ {
9+ public $ tries = 3 ;
10+
11+ /**
12+ * Create a new job instance.
13+ *
14+ * @return void
15+ */
16+ public function __construct ($ delay = null )
17+ {
18+ $ this ->delay = $ delay ;
19+ }
20+
21+ /**
22+ * Execute the job.
23+ *
24+ * @return void
25+ */
26+ public function handle ()
27+ {
28+ event (new JobOutput ('SimpleJobWithDelayProperty:success ' ));
29+ }
30+ }
You can’t perform that action at this time.
0 commit comments