/**
  * A basic test example.
  *
  * @return void
  */
 public function test_send_email_have_clean_exit()
 {
     $company = factory(Company::class)->create();
     $this->mockEmail(env('MAIL_FROM_ADDRESS'), env('MAIL_FROM_NAME'), $company, 'Licence Approval', 'emails.company-approval');
     $this->seeInDatabase('companies', ['id' => $company->id]);
     $sendEmail = new ActionCommandSendApprovalEmailCommand($company->id);
     $actualNumberOfEmailSent = $sendEmail->execute();
     $this->assertEquals(1, $actualNumberOfEmailSent);
 }
Ejemplo n.º 2
0
 /**
  * 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');
 }