feat: Permettre la définition d'une semaine type récurrente pour l'emploi du temps
Some checks failed
CI / Backend Tests (push) Has been cancelled
CI / Frontend Tests (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
CI / Naming Conventions (push) Has been cancelled
CI / Build Check (push) Has been cancelled

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:
2026-03-04 20:03:12 +01:00
parent e156755b86
commit ae640e91ac
35 changed files with 3550 additions and 81 deletions

View File

@@ -0,0 +1,173 @@
<?php
declare(strict_types=1);
namespace App\Tests\Unit\Scolarite\Application\Command\UpdateRecurringSlot;
use App\Administration\Domain\Model\SchoolClass\ClassId;
use App\Administration\Domain\Model\Subject\SubjectId;
use App\Administration\Domain\Model\User\UserId;
use App\Scolarite\Application\Command\UpdateRecurringSlot\UpdateRecurringSlotCommand;
use App\Scolarite\Application\Command\UpdateRecurringSlot\UpdateRecurringSlotHandler;
use App\Scolarite\Domain\Model\Schedule\DayOfWeek;
use App\Scolarite\Domain\Model\Schedule\ScheduleExceptionType;
use App\Scolarite\Domain\Model\Schedule\ScheduleSlot;
use App\Scolarite\Domain\Model\Schedule\TimeSlot;
use App\Scolarite\Infrastructure\Persistence\InMemory\InMemoryScheduleExceptionRepository;
use App\Scolarite\Infrastructure\Persistence\InMemory\InMemoryScheduleSlotRepository;
use App\Shared\Domain\Clock;
use App\Shared\Domain\Tenant\TenantId;
use DateTimeImmutable;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
final class UpdateRecurringSlotHandlerTest extends TestCase
{
private const string TENANT_ID = '550e8400-e29b-41d4-a716-446655440001';
private const string CLASS_ID = '550e8400-e29b-41d4-a716-446655440020';
private const string SUBJECT_ID = '550e8400-e29b-41d4-a716-446655440030';
private const string TEACHER_ID = '550e8400-e29b-41d4-a716-446655440010';
private const string NEW_TEACHER_ID = '550e8400-e29b-41d4-a716-446655440011';
private const string UPDATER_ID = '550e8400-e29b-41d4-a716-446655440099';
private InMemoryScheduleSlotRepository $slotRepository;
private InMemoryScheduleExceptionRepository $exceptionRepository;
private UpdateRecurringSlotHandler $handler;
protected function setUp(): void
{
$this->slotRepository = new InMemoryScheduleSlotRepository();
$this->exceptionRepository = new InMemoryScheduleExceptionRepository();
$clock = new class implements Clock {
public function now(): DateTimeImmutable
{
return new DateTimeImmutable('2026-10-01 10:00:00');
}
};
$this->handler = new UpdateRecurringSlotHandler(
$this->slotRepository,
$this->exceptionRepository,
$clock,
);
}
#[Test]
public function thisOccurrenceCreatesAnException(): void
{
$slot = $this->createAndSaveSlot();
$command = new UpdateRecurringSlotCommand(
tenantId: self::TENANT_ID,
slotId: (string) $slot->id,
occurrenceDate: '2026-10-05',
scope: 'this_occurrence',
classId: self::CLASS_ID,
subjectId: self::SUBJECT_ID,
teacherId: self::NEW_TEACHER_ID,
dayOfWeek: DayOfWeek::MONDAY->value,
startTime: '10:00',
endTime: '11:00',
room: 'Salle 301',
updatedBy: self::UPDATER_ID,
);
$result = ($this->handler)($command);
self::assertNotNull($result['exception']);
self::assertSame(ScheduleExceptionType::MODIFIED, $result['exception']->type);
self::assertSame('10:00', $result['exception']->newTimeSlot->startTime);
self::assertSame('Salle 301', $result['exception']->newRoom);
}
#[Test]
public function allFutureEndCurrentRecurrenceAndCreatesNewSlot(): void
{
$slot = $this->createAndSaveSlot(
recurrenceStart: new DateTimeImmutable('2026-09-01'),
recurrenceEnd: new DateTimeImmutable('2027-07-04'),
);
$command = new UpdateRecurringSlotCommand(
tenantId: self::TENANT_ID,
slotId: (string) $slot->id,
occurrenceDate: '2026-10-12',
scope: 'all_future',
classId: self::CLASS_ID,
subjectId: self::SUBJECT_ID,
teacherId: self::NEW_TEACHER_ID,
dayOfWeek: DayOfWeek::MONDAY->value,
startTime: '10:00',
endTime: '11:00',
room: 'Salle 301',
updatedBy: self::UPDATER_ID,
);
$result = ($this->handler)($command);
// Original slot's recurrence ends before the change date
$tenantId = TenantId::fromString(self::TENANT_ID);
$updatedOriginal = $this->slotRepository->get($slot->id, $tenantId);
self::assertSame('2026-10-11', $updatedOriginal->recurrenceEnd->format('Y-m-d'));
// New slot starts from the change date
self::assertNotNull($result['newSlot']);
self::assertSame('2026-10-12', $result['newSlot']->recurrenceStart->format('Y-m-d'));
self::assertSame('2027-07-04', $result['newSlot']->recurrenceEnd->format('Y-m-d'));
self::assertSame('10:00', $result['newSlot']->timeSlot->startTime);
self::assertTrue($result['newSlot']->teacherId->equals(UserId::fromString(self::NEW_TEACHER_ID)));
}
#[Test]
public function allFutureWithNoOriginalEndUsesNullForNewSlotEnd(): void
{
$slot = $this->createAndSaveSlot(
recurrenceStart: new DateTimeImmutable('2026-09-01'),
recurrenceEnd: null,
);
$command = new UpdateRecurringSlotCommand(
tenantId: self::TENANT_ID,
slotId: (string) $slot->id,
occurrenceDate: '2026-10-12',
scope: 'all_future',
classId: self::CLASS_ID,
subjectId: self::SUBJECT_ID,
teacherId: self::TEACHER_ID,
dayOfWeek: DayOfWeek::MONDAY->value,
startTime: '10:00',
endTime: '11:00',
room: null,
updatedBy: self::UPDATER_ID,
);
$result = ($this->handler)($command);
self::assertNotNull($result['newSlot']);
self::assertNull($result['newSlot']->recurrenceEnd);
}
private function createAndSaveSlot(
?DateTimeImmutable $recurrenceStart = null,
?DateTimeImmutable $recurrenceEnd = null,
): ScheduleSlot {
$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,
);
$this->slotRepository->save($slot);
return $slot;
}
}