repository = new InMemoryScheduleSlotRepository(); $clock = new class implements Clock { public function now(): DateTimeImmutable { return new DateTimeImmutable('2026-03-02 15:00:00'); } }; $this->handler = new DeleteScheduleSlotHandler($this->repository, $clock); } #[Test] public function deletesSlotFromRepository(): void { $slot = $this->createAndSaveSlot(); $tenantId = TenantId::fromString(self::TENANT_ID); ($this->handler)(new DeleteScheduleSlotCommand( tenantId: self::TENANT_ID, slotId: (string) $slot->id, )); self::assertNull($this->repository->findById($slot->id, $tenantId)); } #[Test] public function returnsSlotWithCoursSupprime(): void { $slot = $this->createAndSaveSlot(); $slot->pullDomainEvents(); // Clear creation event $deletedSlot = ($this->handler)(new DeleteScheduleSlotCommand( tenantId: self::TENANT_ID, slotId: (string) $slot->id, )); $events = $deletedSlot->pullDomainEvents(); self::assertCount(1, $events); self::assertInstanceOf(CoursSupprime::class, $events[0]); } #[Test] public function throwsWhenSlotNotFound(): void { $this->expectException(ScheduleSlotNotFoundException::class); ($this->handler)(new DeleteScheduleSlotCommand( tenantId: self::TENANT_ID, slotId: '550e8400-e29b-41d4-a716-446655440099', )); } private function createAndSaveSlot(): 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-03-01 10:00:00'), ); $this->repository->save($slot); return $slot; } }