diff --git a/src/GO/Scheduler.php b/src/GO/Scheduler.php index f9ed7f6..294a645 100644 --- a/src/GO/Scheduler.php +++ b/src/GO/Scheduler.php @@ -149,13 +149,16 @@ public function raw($command, $args = [], $id = null) /** * Run the scheduler. * + * @param DateTime $runTime Optional, run at specific moment * @return array Executed jobs */ - public function run() + public function run($runTime = null) { $jobs = $this->getQueuedJobs(); - $runTime = new DateTime('now'); + if (is_null($runTime)) { + $runTime = new DateTime('now'); + } foreach ($jobs as $job) { if ($job->isDue($runTime)) { diff --git a/tests/GO/SchedulerTest.php b/tests/GO/SchedulerTest.php index 70fb4ae..731cfd0 100644 --- a/tests/GO/SchedulerTest.php +++ b/tests/GO/SchedulerTest.php @@ -1,5 +1,6 @@ assertEquals(2, count($executed)); } + + public function testShouldRunAtSpecificTime() + { + $scheduler = new Scheduler(); + $runTime = new DateTime('2017-09-13 00:00:00'); + + $scheduler->call(function () { + // do nothing + })->daily('00:00'); + + $executed = $scheduler->run($runTime); + + $this->assertEquals(1, count($executed)); + } }