at the end of the day, it was inevitable

This commit is contained in:
Mo Elzubeir
2022-12-09 08:36:26 -06:00
commit 1218570914
1768 changed files with 887087 additions and 0 deletions
@@ -0,0 +1,119 @@
<?php
namespace UserBundle\Entity\Notification\Schedule;
use Doctrine\ORM\Mapping as ORM;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Class DailyNotificationScheduleTest
*/
class DailyNotificationScheduleTest extends TestCase
{
/**
* @return void
*/
public function testComputeDate()
{
$schedule = DailyNotificationSchedule::create()
->setDays(DailyNotificationSchedule::DAYS_ALL)
->setTime(DailyNotificationSchedule::TIME_30_M);
$start = new \DateTime();
$start->setTime($start->format('H'), $start->format('i'), 0);
$end = clone $start;
$end->modify('+ 1 day');
$dates = $schedule->computeDates($start, $end);
/** @var \DateTime $date */
$checkStart = clone $start;
foreach ($dates as $date) {
$this->assertSame(
$checkStart->modify('+ 30 minute')->format('c'),
$date->format('c')
);
}
}
/**
* @return void
*/
public function testComputeDateWeekends()
{
$schedule = DailyNotificationSchedule::create()
->setDays(DailyNotificationSchedule::DAYS_WEEKENDS)
->setTime(DailyNotificationSchedule::TIME_4_H);
$start = new \DateTime();
$start->modify('first friday');
$start->setTime(23, 0, 0);
$end = clone $start;
$end->modify('+ 1 day');
$dates = $schedule->computeDates($start, $end);
/** @var \DateTime $date */
$checkStart = clone $start;
foreach ($dates as $date) {
$this->assertSame(
$checkStart->modify('+ 4 hour')->format('c'),
$date->format('c')
);
$this->assertLessThanOrEqual((int) $date->format('N'), 5);
}
}
/**
* @return void
*/
public function testComputeDateWeekdays()
{
$schedule = DailyNotificationSchedule::create()
->setDays(DailyNotificationSchedule::DAYS_WEEKDAYS)
->setTime(DailyNotificationSchedule::TIME_1_H);
$start = new \DateTime();
$start->modify('first sunday');
$start->setTime(23, 0, 0);
$end = clone $start;
$end->modify('+ 1 day');
$dates = $schedule->computeDates($start, $end);
/** @var \DateTime $date */
$checkStart = clone $start;
foreach ($dates as $date) {
$this->assertSame(
$checkStart->modify('+ 1 hour')->format('c'),
$date->format('c')
);
$this->assertGreaterThan((int) $date->format('N'), 5);
}
}
/**
* @return void
*/
public function testComputeDateWithSpecifiedDates()
{
$schedule = DailyNotificationSchedule::create()
->setDays(DailyNotificationSchedule::DAYS_ALL)
->setTime(DailyNotificationSchedule::TIME_15_M);
$start = new \DateTime();
$start
->setDate(2017, 6, 9)
->setTime(0, 0, 0);
$end = clone $start;
$end->modify('+ 30 minutes');
$dates = $schedule->computeDates($start, $end);
$this->assertCount(2, $dates);
$this->assertSame('2017-06-09 00:15:00', $dates[0]->format('Y-m-d H:i:s'));
$this->assertSame('2017-06-09 00:30:00', $dates[1]->format('Y-m-d H:i:s'));
}
}
@@ -0,0 +1,109 @@
<?php
namespace UserBundle\Entity\Notification\Schedule;
use Doctrine\ORM\Mapping as ORM;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Class MonthlyNotificationScheduleTest
*
* @ORM\Entity
*/
class MonthlyNotificationScheduleTest extends TestCase
{
/**
* @return void
*/
public function testComputeDate()
{
$schedule = MonthlyNotificationSchedule::create()
->setDay(5)
->setHour(12)
->setMinute(35);
$start = date_create()->modify('first day of this month')->setTime(0, 0, 0);
$end = date_create()->modify('last day of next month')->setTime(0, 0, 0);
$dates = $schedule->computeDates($start, $end);
$this->assertCount(2, $dates);
$this->assertSame($dates[0]->format('Y-m-d'), date_create()->modify('first day of this month')->modify('4 day')->format('Y-m-d'));
$this->assertSame(5, (int) $dates[0]->format('j'));
$this->assertSame(12, (int) $dates[0]->format('H'));
$this->assertSame(35, (int) $dates[0]->format('i'));
$this->assertSame($dates[1]->format('Y-m-d'), date_create()->modify('first day of next month')->modify('4 day')->format('Y-m-d'));
$this->assertSame(5, (int) $dates[1]->format('j'));
$this->assertSame(12, (int) $dates[1]->format('H'));
$this->assertSame(35, (int) $dates[1]->format('i'));
$schedule = MonthlyNotificationSchedule::create()
->setDay(2)
->setHour(8)
->setMinute(50);
$start = date_create()->modify('first day of this month')->modify('1 day')->setTime(0, 0, 0);
$end = date_create()->modify('next month')->modify('first day of next month')->modify('1 day')->setTime(0, 0, 0);
$dates = $schedule->computeDates($start, $end);
$this->assertCount(3, $dates);
$this->assertSame($dates[0]->format('Y-m-d'), date_create()->modify('first day of this month')->modify('1 day')->format('Y-m-d'));
$this->assertSame(2, (int) $dates[0]->format('j'));
$this->assertSame(8, (int) $dates[0]->format('H'));
$this->assertSame(50, (int) $dates[0]->format('i'));
$this->assertSame($dates[1]->format('Y-m-d'), date_create()->modify('first day of next month')->modify('1 day')->format('Y-m-d'));
$this->assertSame(2, (int) $dates[1]->format('j'));
$this->assertSame(8, (int) $dates[1]->format('H'));
$this->assertSame(50, (int) $dates[1]->format('i'));
$this->assertSame($dates[2]->format('Y-m-d'), date_create()->modify('next month')->modify('first day of next month')->modify('1 day')->format('Y-m-d'));
$this->assertSame(2, (int) $dates[2]->format('j'));
$this->assertSame(8, (int) $dates[2]->format('H'));
$this->assertSame(50, (int) $dates[2]->format('i'));
}
/**
* @return void
*/
public function testComputeDateLast()
{
$schedule = MonthlyNotificationSchedule::create()
->setDay(MonthlyNotificationSchedule::DAY_LAST)
->setHour(12)
->setMinute(35);
$start = date_create()->modify('first day of this month')->setTime(0, 0, 0);
$end = date_create()->modify('last day of next month')->setTime(0, 0, 0);
$dates = $schedule->computeDates($start, $end);
$this->assertCount(2, $dates);
$this->assertSame($dates[0]->format('Y-m-d'), date_create()->modify('last day of this month')->format('Y-m-d'));
$this->assertSame(12, (int) $dates[0]->format('H'));
$this->assertSame(35, (int) $dates[0]->format('i'));
$this->assertSame($dates[1]->format('Y-m-d'), date_create()->modify('last day of next month')->format('Y-m-d'));
$this->assertSame(12, (int) $dates[1]->format('H'));
$this->assertSame(35, (int) $dates[1]->format('i'));
$schedule = MonthlyNotificationSchedule::create()
->setDay(MonthlyNotificationSchedule::DAY_LAST)
->setHour(2)
->setMinute(15);
$start = date_create()->modify('last day of this month')->setTime(0, 0, 0);
$end = date_create()->modify('first day of next month')->setTime(0, 0, 0);
$dates = $schedule->computeDates($start, $end);
$this->assertCount(1, $dates);
$this->assertSame($dates[0]->format('Y-m-d'), date_create()->modify('last day of this month')->format('Y-m-d'));
$this->assertSame(2, (int) $dates[0]->format('H'));
$this->assertSame(15, (int) $dates[0]->format('i'));
}
}
@@ -0,0 +1,117 @@
<?php
namespace UserBundle\Entity\Notification\Schedule;
use Doctrine\ORM\Mapping as ORM;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Class WeeklyNotificationSchedule
*
* @ORM\Entity
*/
class WeeklyNotificationScheduleTest extends TestCase
{
/**
* @return void
*/
public function testComputeDate()
{
$schedule = WeeklyNotificationSchedule::create()
->setPeriod(WeeklyNotificationSchedule::PERIOD_SECOND)
->setDay(WeeklyNotificationSchedule::DAY_FRIDAY)
->setHour(12)
->setMinute(35);
$start = date_create()->modify('first day of this month')->setTime(0, 0, 0);
$end = date_create()->modify('second friday of next month')->setTime(0, 0, 0);
$dates = $schedule->computeDates($start, $end);
$this->assertCount(2, $dates);
$this->assertSame($dates[0]->format('Y-m-d'), date_create()->modify('second friday of this month')->format('Y-m-d'));
$this->assertSame(12, (int) $dates[0]->format('H'));
$this->assertSame(35, (int) $dates[0]->format('i'));
$this->assertSame($dates[1]->format('Y-m-d'), date_create()->modify('second friday of next month')->format('Y-m-d'));
$this->assertSame(12, (int) $dates[1]->format('H'));
$this->assertSame(35, (int) $dates[1]->format('i'));
$schedule = WeeklyNotificationSchedule::create()
->setPeriod(WeeklyNotificationSchedule::PERIOD_FIRST)
->setDay(WeeklyNotificationSchedule::DAY_TUESDAY);
$start = date_create()->modify('first day of this month')->setTime(0, 0, 0);
$end = date_create()->modify('second friday of next month')->setTime(0, 0, 0);
$dates = $schedule->computeDates($start, $end);
$this->assertCount(2, $dates);
$this->assertSame($dates[0]->format('Y-m-d'), date_create()->modify('first tuesday of this month')->format('Y-m-d'));
$this->assertSame(0, (int) $dates[0]->format('H'));
$this->assertSame(0, (int) $dates[0]->format('i'));
$this->assertSame($dates[1]->format('Y-m-d'), date_create()->modify('first tuesday of next month')->format('Y-m-d'));
$this->assertSame(0, (int) $dates[1]->format('H'));
$this->assertSame(0, (int) $dates[1]->format('i'));
}
/**
* @return void
*/
public function testComputeDateEvery()
{
$schedule = WeeklyNotificationSchedule::create()
->setPeriod(WeeklyNotificationSchedule::PERIOD_EVERY)
->setDay(WeeklyNotificationSchedule::DAY_MONDAY)
->setHour(10)
->setMinute(45);
$start = date_create()->modify('first day of this month')->setTime(0, 0, 0);
$end = date_create()->modify('last day of next month')->setTime(0, 0, 0);
$dates = $schedule->computeDates($start, $end);
/** @var \DateTime $date */
foreach ($dates as $date) {
$this->assertSame(
1,
(int) $date->format('N')
);
$this->assertSame(10, (int) $date->format('H'));
$this->assertSame(45, (int) $date->format('i'));
}
}
/**
* @return void
*/
public function testComputeDateLast()
{
$schedule = WeeklyNotificationSchedule::create()
->setPeriod(WeeklyNotificationSchedule::PERIOD_LAST)
->setDay(WeeklyNotificationSchedule::DAY_SUNDAY)
->setHour(10)
->setMinute(45);
$start = date_create()->modify('first day of this month')->setTime(0, 0, 0);
$end = date_create()->modify('next month')->modify('last day of next month')->setTime(0, 0, 0);
$dates = $schedule->computeDates($start, $end);
$this->assertCount(3, $dates);
$this->assertSame($dates[0]->format('Y-m-d'), date_create()->modify('last sunday of this month')->format('Y-m-d'));
$this->assertSame(10, (int) $dates[0]->format('H'));
$this->assertSame(45, (int) $dates[0]->format('i'));
$this->assertSame($dates[1]->format('Y-m-d'), date_create()->modify('last sunday of next month')->format('Y-m-d'));
$this->assertSame(10, (int) $dates[1]->format('H'));
$this->assertSame(45, (int) $dates[1]->format('i'));
$this->assertSame($dates[2]->format('Y-m-d'), date_create()->modify('next month')->modify('last sunday of next month')->format('Y-m-d'));
$this->assertSame(10, (int) $dates[2]->format('H'));
$this->assertSame(45, (int) $dates[2]->format('i'));
}
}