feat: Permettre la définition d'une semaine type récurrente pour l'emploi du temps
Les administrateurs devaient recréer manuellement l'emploi du temps chaque semaine. Cette implémentation introduit un système de récurrence hebdomadaire avec gestion des exceptions par occurrence, permettant de modifier ou annuler un cours spécifique sans affecter les autres semaines. Le ScheduleResolver calcule dynamiquement l'EDT réel en combinant les créneaux récurrents, les exceptions ponctuelles et le calendrier scolaire (vacances/fériés).
This commit is contained in:
@@ -176,6 +176,161 @@ final class ScheduleSlotTest extends TestCase
|
||||
self::assertEmpty($slot->pullDomainEvents());
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function creerWithRecurrenceBoundsSetsDates(): void
|
||||
{
|
||||
$recurrenceStart = new DateTimeImmutable('2026-09-01');
|
||||
$recurrenceEnd = new DateTimeImmutable('2027-07-04');
|
||||
|
||||
$slot = ScheduleSlot::creer(
|
||||
tenantId: TenantId::fromString(self::TENANT_ID),
|
||||
classId: ClassId::fromString(self::CLASS_ID),
|
||||
subjectId: SubjectId::fromString(self::SUBJECT_ID),
|
||||
teacherId: UserId::fromString(self::TEACHER_ID),
|
||||
dayOfWeek: DayOfWeek::MONDAY,
|
||||
timeSlot: new TimeSlot('08:00', '09:00'),
|
||||
room: null,
|
||||
isRecurring: true,
|
||||
now: new DateTimeImmutable('2026-09-01 10:00:00'),
|
||||
recurrenceStart: $recurrenceStart,
|
||||
recurrenceEnd: $recurrenceEnd,
|
||||
);
|
||||
|
||||
self::assertEquals($recurrenceStart, $slot->recurrenceStart);
|
||||
self::assertEquals($recurrenceEnd, $slot->recurrenceEnd);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function creerWithoutRecurrenceBoundsDefaultsToNull(): void
|
||||
{
|
||||
$slot = $this->createSlot();
|
||||
|
||||
self::assertNull($slot->recurrenceStart);
|
||||
self::assertNull($slot->recurrenceEnd);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function isActiveOnDateReturnsTrueForMatchingDayWithinBounds(): void
|
||||
{
|
||||
$slot = $this->createRecurringSlot(
|
||||
dayOfWeek: DayOfWeek::MONDAY,
|
||||
recurrenceStart: new DateTimeImmutable('2026-09-01'),
|
||||
recurrenceEnd: new DateTimeImmutable('2027-07-04'),
|
||||
);
|
||||
|
||||
// 2026-09-07 is a Monday within bounds
|
||||
self::assertTrue($slot->isActiveOnDate(new DateTimeImmutable('2026-09-07')));
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function isActiveOnDateReturnsFalseForWrongDayOfWeek(): void
|
||||
{
|
||||
$slot = $this->createRecurringSlot(
|
||||
dayOfWeek: DayOfWeek::MONDAY,
|
||||
recurrenceStart: new DateTimeImmutable('2026-09-01'),
|
||||
recurrenceEnd: new DateTimeImmutable('2027-07-04'),
|
||||
);
|
||||
|
||||
// 2026-09-08 is a Tuesday
|
||||
self::assertFalse($slot->isActiveOnDate(new DateTimeImmutable('2026-09-08')));
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function isActiveOnDateReturnsFalseBeforeRecurrenceStart(): void
|
||||
{
|
||||
$slot = $this->createRecurringSlot(
|
||||
dayOfWeek: DayOfWeek::MONDAY,
|
||||
recurrenceStart: new DateTimeImmutable('2026-09-01'),
|
||||
recurrenceEnd: new DateTimeImmutable('2027-07-04'),
|
||||
);
|
||||
|
||||
// 2026-08-25 is a Monday but before start
|
||||
self::assertFalse($slot->isActiveOnDate(new DateTimeImmutable('2026-08-25')));
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function isActiveOnDateReturnsFalseAfterRecurrenceEnd(): void
|
||||
{
|
||||
$slot = $this->createRecurringSlot(
|
||||
dayOfWeek: DayOfWeek::MONDAY,
|
||||
recurrenceStart: new DateTimeImmutable('2026-09-01'),
|
||||
recurrenceEnd: new DateTimeImmutable('2027-07-04'),
|
||||
);
|
||||
|
||||
// 2027-07-07 is a Monday but after end
|
||||
self::assertFalse($slot->isActiveOnDate(new DateTimeImmutable('2027-07-07')));
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function isActiveOnDateReturnsTrueWithNoBounds(): void
|
||||
{
|
||||
$slot = $this->createRecurringSlot(
|
||||
dayOfWeek: DayOfWeek::MONDAY,
|
||||
recurrenceStart: null,
|
||||
recurrenceEnd: null,
|
||||
);
|
||||
|
||||
// Any Monday should work
|
||||
self::assertTrue($slot->isActiveOnDate(new DateTimeImmutable('2026-09-07')));
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function isActiveOnDateReturnsFalseForNonRecurringSlot(): void
|
||||
{
|
||||
$slot = ScheduleSlot::creer(
|
||||
tenantId: TenantId::fromString(self::TENANT_ID),
|
||||
classId: ClassId::fromString(self::CLASS_ID),
|
||||
subjectId: SubjectId::fromString(self::SUBJECT_ID),
|
||||
teacherId: UserId::fromString(self::TEACHER_ID),
|
||||
dayOfWeek: DayOfWeek::MONDAY,
|
||||
timeSlot: new TimeSlot('08:00', '09:00'),
|
||||
room: null,
|
||||
isRecurring: false,
|
||||
now: new DateTimeImmutable('2026-09-01 10:00:00'),
|
||||
);
|
||||
|
||||
self::assertFalse($slot->isActiveOnDate(new DateTimeImmutable('2026-09-07')));
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function isActiveOnDateIncludesBoundaryDates(): void
|
||||
{
|
||||
$slot = $this->createRecurringSlot(
|
||||
dayOfWeek: DayOfWeek::MONDAY,
|
||||
recurrenceStart: new DateTimeImmutable('2026-09-07'),
|
||||
recurrenceEnd: new DateTimeImmutable('2026-09-07'),
|
||||
);
|
||||
|
||||
// Exact start = exact end date
|
||||
self::assertTrue($slot->isActiveOnDate(new DateTimeImmutable('2026-09-07')));
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function reconstituteRestoresRecurrenceBounds(): void
|
||||
{
|
||||
$recurrenceStart = new DateTimeImmutable('2026-09-01');
|
||||
$recurrenceEnd = new DateTimeImmutable('2027-07-04');
|
||||
|
||||
$slot = ScheduleSlot::reconstitute(
|
||||
id: ScheduleSlotId::generate(),
|
||||
tenantId: TenantId::fromString(self::TENANT_ID),
|
||||
classId: ClassId::fromString(self::CLASS_ID),
|
||||
subjectId: SubjectId::fromString(self::SUBJECT_ID),
|
||||
teacherId: UserId::fromString(self::TEACHER_ID),
|
||||
dayOfWeek: DayOfWeek::FRIDAY,
|
||||
timeSlot: new TimeSlot('14:00', '15:30'),
|
||||
room: null,
|
||||
isRecurring: true,
|
||||
createdAt: new DateTimeImmutable('2026-03-01 10:00:00'),
|
||||
updatedAt: new DateTimeImmutable('2026-03-02 14:00:00'),
|
||||
recurrenceStart: $recurrenceStart,
|
||||
recurrenceEnd: $recurrenceEnd,
|
||||
);
|
||||
|
||||
self::assertEquals($recurrenceStart, $slot->recurrenceStart);
|
||||
self::assertEquals($recurrenceEnd, $slot->recurrenceEnd);
|
||||
}
|
||||
|
||||
private function createSlot(?string $room = null): ScheduleSlot
|
||||
{
|
||||
return ScheduleSlot::creer(
|
||||
@@ -190,4 +345,24 @@ final class ScheduleSlotTest extends TestCase
|
||||
now: new DateTimeImmutable('2026-03-01 10:00:00'),
|
||||
);
|
||||
}
|
||||
|
||||
private function createRecurringSlot(
|
||||
DayOfWeek $dayOfWeek,
|
||||
?DateTimeImmutable $recurrenceStart,
|
||||
?DateTimeImmutable $recurrenceEnd,
|
||||
): ScheduleSlot {
|
||||
return ScheduleSlot::creer(
|
||||
tenantId: TenantId::fromString(self::TENANT_ID),
|
||||
classId: ClassId::fromString(self::CLASS_ID),
|
||||
subjectId: SubjectId::fromString(self::SUBJECT_ID),
|
||||
teacherId: UserId::fromString(self::TEACHER_ID),
|
||||
dayOfWeek: $dayOfWeek,
|
||||
timeSlot: new TimeSlot('08:00', '09:00'),
|
||||
room: null,
|
||||
isRecurring: true,
|
||||
now: new DateTimeImmutable('2026-09-01 10:00:00'),
|
||||
recurrenceStart: $recurrenceStart,
|
||||
recurrenceEnd: $recurrenceEnd,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user