Example #1
0
 public function test_add_company_multiple_reminder_schedules_with_repository()
 {
     $expireAt = '2016-03-30';
     $remindDays = [1, 2, 3];
     $remindAts = [1 => '2016-03-29', 2 => '2016-03-28', 3 => '2016-03-27'];
     //$this->assertInstanceOf('RuntimeException', new \Exception);
     $company = factory(Company::class)->create(['licence_expire_at' => $expireAt]);
     if (!isset($company->licence_expire_at)) {
         throw new \Exception("Licence Expiration Date must be set first!");
     }
     // remove reminders for Company One
     $scheduleRepository = new ScheduleRepository();
     $scheduleRepository->removeAllForObject($company);
     // add multiple actions to schedule
     // dates when to send reminders
     $lrc = new LicenceReminderCalculator();
     $runAts = $lrc->getReminderDates($company->licence_expire_at, $remindDays);
     $this->assertEquals($remindAts, $runAts);
     $action = ActionCommandSendReminderEmailCommand::class;
     $schedules = [];
     foreach ($runAts as $runAt) {
         $schedules[$runAt] = $scheduleRepository->add($runAt, $action, $company, []);
     }
     $this->assertCount(count($remindAts), $schedules);
     foreach ($schedules as $runAt => $schedule) {
         $this->seeInDatabase('schedules', ['run_at' => $runAt, 'id' => $schedule->id]);
     }
 }
 /**
  * Generated from @assert ('2016-01-30', [5, 10, 20]) == [5 =>'2016-01-25',10=>'2016-01-20',20=>'2016-01-10'].
  *
  * @covers App\LicenceReminderCalculator::getReminderDates
  */
 public function testGetReminderDates()
 {
     $expirationDate = '2016-01-30';
     $reminderDays = [5, 10, 20];
     $expectedArr = [5 => '2016-01-25', 10 => '2016-01-20', 20 => '2016-01-10'];
     $lrc = new LicenceReminderCalculator();
     $this->assertEquals($expectedArr, $lrc->getReminderDates($expirationDate, $reminderDays));
 }
 /**
  * A basic test example.
  *
  * @return void
  */
 public function test_read_configuration_for_reminder_days()
 {
     // emulate config set
     $expected = [3, 7, 15];
     $expectedStr = implode(',', $expected);
     \Config::set('custom.remindOnDays', $expectedStr);
     // get config values
     $reminderCalculator = new LicenceReminderCalculator();
     $remindOnDays = $reminderCalculator->getReminderDays();
     // assert
     //
     // Expected to remind for Licence expiration
     // 3, 7, 15 days before expiration day.
     $this->assertEquals($expected, $remindOnDays);
 }
 public function addSendReminderEmail(Company $company, LicenceReminderCalculator $reminderCalculator)
 {
     if (!isset($company->licence_expire_at)) {
         throw new \Exception("Licence Expiration Date must be set first!");
     }
     // get config values in days
     $remindOnDays = $reminderCalculator->getReminderDays();
     // dates when to send reminders
     $runAts = $reminderCalculator->getReminderDates($company->licence_expire_at, $remindOnDays);
     // save reminders in queue
     $action = ActionCommandSendReminderEmailCommand::class;
     $schedules = [];
     foreach ($runAts as $runAt) {
         $schedules[$runAt] = $this->add($runAt, $action, $company, []);
     }
     return $schedules;
 }