public function test_add_company_multiple_reminder_schedules_with_add_command_in_repository() { // prepare $expireAt = '2016-03-30'; $remindDays = [1, 5, 20]; $remindAts = [1 => '2016-03-29', 5 => '2016-03-25', 20 => '2016-03-10']; $company = factory(Company::class)->create(['licence_expire_at' => $expireAt]); // ------------------------------------------ // run $lrc = new LicenceReminderCalculator(); $scheduleRepository = new ScheduleRepository(); $schedules = $scheduleRepository->addSendReminderEmail($company, $lrc); // ------------------------------------------ // assert foreach ($schedules as $runAt => $schedule) { $this->seeInDatabase('schedules', ['run_at' => $runAt, 'id' => $schedule->id]); } }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param \App\Company $company * @return \Illuminate\Http\Response */ public function update(Request $request, Company $company) { $this->authorize('update-company', $company); $this->validate($request, ['name' => 'required|max:255', 'licence_expire_at' => 'date_format:Y-m-d']); $company->name = $request->name; if ($request->licence_expire_at != '') { $company->licence_expire_at = $request->licence_expire_at; $company->is_suspended = false; } $company->save(); // update schedules for SendReminderEmail(s) if (isset($company->licence_expire_at)) { $lrc = new LicenceReminderCalculator(); $scheduleRepository = new ScheduleRepository(); $scheduleRepository->removeAllForObject($company); // send reminders emails on configured days before expiration date $reminders = $scheduleRepository->addSendReminderEmail($company, $lrc); // suspend company on expiration date $suspensions = $scheduleRepository->addSuspendCompany($company); // send suspension emails on expiration date $suspensionEmails = $scheduleRepository->addSendSuspensionEmail($company); // send approval email now $approvalEmail = new ActionCommandSendApprovalEmailCommand($company->id); $approvalEmail->execute(); } return redirect('/companies'); }