auditLogger = $this->createMock(AuditLogger::class); $this->handler = new AuditEvaluationEventsHandler($this->auditLogger); } public function testHandleEvaluationCreeeLogsAuditEntryWithFullPayload(): void { $evaluationId = EvaluationId::generate(); $classId = Uuid::uuid4()->toString(); $subjectId = Uuid::uuid4()->toString(); $teacherId = Uuid::uuid4()->toString(); $evaluationDate = new DateTimeImmutable('2026-04-15'); $event = new EvaluationCreee( evaluationId: $evaluationId, classId: $classId, subjectId: $subjectId, teacherId: $teacherId, title: 'ContrĂ´le chapitre 3', description: 'Sur le chapitre 3 uniquement', evaluationDate: $evaluationDate, gradeScale: 20, coefficient: 2.0, occurredOn: new DateTimeImmutable(), ); $this->auditLogger->expects($this->once()) ->method('logDataChange') ->with( $this->equalTo('Evaluation'), $this->callback(static fn ($uuid) => $uuid->toString() === $evaluationId->value->toString()), $this->equalTo('EvaluationCreee'), $this->equalTo([]), $this->callback(static fn ($new) => $new['title'] === 'ContrĂ´le chapitre 3' && $new['description'] === 'Sur le chapitre 3 uniquement' && $new['class_id'] === $classId && $new['subject_id'] === $subjectId && $new['teacher_id'] === $teacherId && $new['evaluation_date'] === '2026-04-15' && $new['grade_scale'] === 20 && $new['coefficient'] === 2.0 ), ); $this->handler->handleEvaluationCreee($event); } public function testHandleEvaluationModifieeLogsAuditEntryWithDiff(): void { $evaluationId = EvaluationId::generate(); $event = new EvaluationModifiee( evaluationId: $evaluationId, oldTitle: 'Ancien titre', newTitle: 'Nouveau titre', oldDescription: 'Ancienne description', newDescription: 'Nouvelle description', oldCoefficient: 1.0, newCoefficient: 2.0, oldEvaluationDate: new DateTimeImmutable('2026-04-15'), newEvaluationDate: new DateTimeImmutable('2026-05-01'), oldGradeScale: 20, newGradeScale: 100, occurredOn: new DateTimeImmutable(), ); $this->auditLogger->expects($this->once()) ->method('logDataChange') ->with( $this->equalTo('Evaluation'), $this->callback(static fn ($uuid) => $uuid->toString() === $evaluationId->value->toString()), $this->equalTo('EvaluationModifiee'), $this->callback(static fn ($old) => $old['title'] === 'Ancien titre' && $old['description'] === 'Ancienne description' && $old['coefficient'] === 1.0 && $old['evaluation_date'] === '2026-04-15' && $old['grade_scale'] === 20 ), $this->callback(static fn ($new) => $new['title'] === 'Nouveau titre' && $new['description'] === 'Nouvelle description' && $new['coefficient'] === 2.0 && $new['evaluation_date'] === '2026-05-01' && $new['grade_scale'] === 100 ), ); $this->handler->handleEvaluationModifiee($event); } public function testHandleEvaluationSupprimeeLogsAuditEntry(): void { $evaluationId = EvaluationId::generate(); $event = new EvaluationSupprimee( evaluationId: $evaluationId, occurredOn: new DateTimeImmutable(), ); $this->auditLogger->expects($this->once()) ->method('logDataChange') ->with( $this->equalTo('Evaluation'), $this->callback(static fn ($uuid) => $uuid->toString() === $evaluationId->value->toString()), $this->equalTo('EvaluationSupprimee'), $this->equalTo([]), $this->equalTo([]), ); $this->handler->handleEvaluationSupprimee($event); } public function testHandleNotesPublieesLogsAuditEntry(): void { $evaluationId = EvaluationId::generate(); $event = new NotesPubliees( evaluationId: $evaluationId, occurredOn: new DateTimeImmutable(), ); $this->auditLogger->expects($this->once()) ->method('logDataChange') ->with( $this->equalTo('Evaluation'), $this->callback(static fn ($uuid) => $uuid->toString() === $evaluationId->value->toString()), $this->equalTo('NotesPubliees'), $this->equalTo([]), $this->equalTo([]), ); $this->handler->handleNotesPubliees($event); } }