repository = m::mock(ScheduleRepositoryInterface::class); $this->runnerService = m::mock(RunTaskService::class); $this->service = new ProcessScheduleService($this->runnerService, $this->repository); } /** * Test that a schedule can be updated and first task set to run. */ public function testScheduleIsUpdatedAndRun() { $model = factory(Schedule::class)->make(); $model->setRelation('tasks', collect([$task = factory(Task::class)->make([ 'sequence_id' => 1, ])])); $this->repository->shouldReceive('loadTasks')->with($model)->once()->andReturn($model); $formatted = sprintf('%s %s %s * %s', $model->cron_minute, $model->cron_hour, $model->cron_day_of_month, $model->cron_day_of_week); $this->repository->shouldReceive('update')->with($model->id, [ 'is_processing' => true, 'next_run_at' => CronExpression::factory($formatted)->getNextRunDate(), ]); $this->runnerService->shouldReceive('handle')->with($task)->once()->andReturnNull(); $this->service->handle($model); $this->assertTrue(true); } public function testScheduleRunTimeCanBeOverridden() { $model = factory(Schedule::class)->make(); $model->setRelation('tasks', collect([$task = factory(Task::class)->make([ 'sequence_id' => 1, ])])); $this->repository->shouldReceive('loadTasks')->with($model)->once()->andReturn($model); $this->repository->shouldReceive('update')->with($model->id, [ 'is_processing' => true, 'next_run_at' => Carbon::now()->addSeconds(15)->toDateTimeString(), ]); $this->runnerService->shouldReceive('handle')->with($task)->once()->andReturnNull(); $this->service->setRunTimeOverride(Carbon::now()->addSeconds(15))->handle($model); $this->assertTrue(true); } }