feat: Configuration du mode de notation par établissement
Les établissements scolaires utilisent des systèmes d'évaluation variés (notes /20, /10, lettres, compétences, sans notes). Jusqu'ici l'application imposait implicitement le mode notes /20, ce qui ne correspondait pas à la réalité pédagogique de nombreuses écoles. Cette configuration permet à chaque établissement de choisir son mode de notation par année scolaire, avec verrouillage automatique dès que des notes ont été saisies pour éviter les incohérences. Le Score Sérénité adapte ses pondérations selon le mode choisi (les compétences sont converties via un mapping, le mode sans notes exclut la composante notes).
This commit is contained in:
@@ -0,0 +1,226 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Unit\Administration\Application\Command\ConfigureGradingMode;
|
||||
|
||||
use App\Administration\Application\Command\ConfigureGradingMode\ConfigureGradingModeCommand;
|
||||
use App\Administration\Application\Command\ConfigureGradingMode\ConfigureGradingModeHandler;
|
||||
use App\Administration\Application\Port\GradeExistenceChecker;
|
||||
use App\Administration\Domain\Exception\CannotChangeGradingModeWithExistingGradesException;
|
||||
use App\Administration\Domain\Model\GradingConfiguration\GradingMode;
|
||||
use App\Administration\Domain\Model\SchoolClass\AcademicYearId;
|
||||
use App\Administration\Domain\Model\SchoolClass\SchoolId;
|
||||
use App\Administration\Infrastructure\Persistence\InMemory\InMemoryGradingConfigurationRepository;
|
||||
use App\Shared\Domain\Clock;
|
||||
use App\Shared\Domain\Tenant\TenantId;
|
||||
use DateTimeImmutable;
|
||||
use Override;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class ConfigureGradingModeHandlerTest extends TestCase
|
||||
{
|
||||
private const string TENANT_ID = '550e8400-e29b-41d4-a716-446655440001';
|
||||
private const string SCHOOL_ID = '550e8400-e29b-41d4-a716-446655440002';
|
||||
private const string ACADEMIC_YEAR_ID = '550e8400-e29b-41d4-a716-446655440003';
|
||||
|
||||
private InMemoryGradingConfigurationRepository $repository;
|
||||
private Clock $clock;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->repository = new InMemoryGradingConfigurationRepository();
|
||||
$this->clock = new class implements Clock {
|
||||
#[Override]
|
||||
public function now(): DateTimeImmutable
|
||||
{
|
||||
return new DateTimeImmutable('2026-02-01 10:00:00');
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function itCreatesNewConfigurationWhenNoneExists(): void
|
||||
{
|
||||
$handler = $this->createHandler(hasGrades: false);
|
||||
|
||||
$result = $handler(new ConfigureGradingModeCommand(
|
||||
tenantId: self::TENANT_ID,
|
||||
schoolId: self::SCHOOL_ID,
|
||||
academicYearId: self::ACADEMIC_YEAR_ID,
|
||||
gradingMode: 'numeric_20',
|
||||
));
|
||||
|
||||
self::assertSame(GradingMode::NUMERIC_20, $result->gradingConfiguration->mode);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function itPersistsConfigurationInRepository(): void
|
||||
{
|
||||
$handler = $this->createHandler(hasGrades: false);
|
||||
|
||||
$handler(new ConfigureGradingModeCommand(
|
||||
tenantId: self::TENANT_ID,
|
||||
schoolId: self::SCHOOL_ID,
|
||||
academicYearId: self::ACADEMIC_YEAR_ID,
|
||||
gradingMode: 'competencies',
|
||||
));
|
||||
|
||||
$found = $this->repository->findBySchoolAndYear(
|
||||
TenantId::fromString(self::TENANT_ID),
|
||||
SchoolId::fromString(self::SCHOOL_ID),
|
||||
AcademicYearId::fromString(self::ACADEMIC_YEAR_ID),
|
||||
);
|
||||
|
||||
self::assertNotNull($found);
|
||||
self::assertSame(GradingMode::COMPETENCIES, $found->gradingConfiguration->mode);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function itChangesExistingModeWhenNoGradesExist(): void
|
||||
{
|
||||
$handler = $this->createHandler(hasGrades: false);
|
||||
|
||||
$handler(new ConfigureGradingModeCommand(
|
||||
tenantId: self::TENANT_ID,
|
||||
schoolId: self::SCHOOL_ID,
|
||||
academicYearId: self::ACADEMIC_YEAR_ID,
|
||||
gradingMode: 'numeric_20',
|
||||
));
|
||||
|
||||
$result = $handler(new ConfigureGradingModeCommand(
|
||||
tenantId: self::TENANT_ID,
|
||||
schoolId: self::SCHOOL_ID,
|
||||
academicYearId: self::ACADEMIC_YEAR_ID,
|
||||
gradingMode: 'letters',
|
||||
));
|
||||
|
||||
self::assertSame(GradingMode::LETTERS, $result->gradingConfiguration->mode);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function itBlocksChangeWhenGradesExist(): void
|
||||
{
|
||||
$handlerNoGrades = $this->createHandler(hasGrades: false);
|
||||
$handlerNoGrades(new ConfigureGradingModeCommand(
|
||||
tenantId: self::TENANT_ID,
|
||||
schoolId: self::SCHOOL_ID,
|
||||
academicYearId: self::ACADEMIC_YEAR_ID,
|
||||
gradingMode: 'numeric_20',
|
||||
));
|
||||
|
||||
$handlerWithGrades = $this->createHandler(hasGrades: true);
|
||||
|
||||
$this->expectException(CannotChangeGradingModeWithExistingGradesException::class);
|
||||
|
||||
$handlerWithGrades(new ConfigureGradingModeCommand(
|
||||
tenantId: self::TENANT_ID,
|
||||
schoolId: self::SCHOOL_ID,
|
||||
academicYearId: self::ACADEMIC_YEAR_ID,
|
||||
gradingMode: 'competencies',
|
||||
));
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function itAllowsSameModeEvenWithGradesExisting(): void
|
||||
{
|
||||
$handlerNoGrades = $this->createHandler(hasGrades: false);
|
||||
$handlerNoGrades(new ConfigureGradingModeCommand(
|
||||
tenantId: self::TENANT_ID,
|
||||
schoolId: self::SCHOOL_ID,
|
||||
academicYearId: self::ACADEMIC_YEAR_ID,
|
||||
gradingMode: 'numeric_20',
|
||||
));
|
||||
|
||||
$handlerWithGrades = $this->createHandler(hasGrades: true);
|
||||
$result = $handlerWithGrades(new ConfigureGradingModeCommand(
|
||||
tenantId: self::TENANT_ID,
|
||||
schoolId: self::SCHOOL_ID,
|
||||
academicYearId: self::ACADEMIC_YEAR_ID,
|
||||
gradingMode: 'numeric_20',
|
||||
));
|
||||
|
||||
self::assertSame(GradingMode::NUMERIC_20, $result->gradingConfiguration->mode);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function itBlocksInitialNonDefaultModeWhenGradesExist(): void
|
||||
{
|
||||
$handler = $this->createHandler(hasGrades: true);
|
||||
|
||||
$this->expectException(CannotChangeGradingModeWithExistingGradesException::class);
|
||||
|
||||
$handler(new ConfigureGradingModeCommand(
|
||||
tenantId: self::TENANT_ID,
|
||||
schoolId: self::SCHOOL_ID,
|
||||
academicYearId: self::ACADEMIC_YEAR_ID,
|
||||
gradingMode: 'competencies',
|
||||
));
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function itIsolatesConfigurationByTenant(): void
|
||||
{
|
||||
$handler = $this->createHandler(hasGrades: false);
|
||||
|
||||
$handler(new ConfigureGradingModeCommand(
|
||||
tenantId: self::TENANT_ID,
|
||||
schoolId: self::SCHOOL_ID,
|
||||
academicYearId: self::ACADEMIC_YEAR_ID,
|
||||
gradingMode: 'numeric_20',
|
||||
));
|
||||
|
||||
$otherTenantId = '550e8400-e29b-41d4-a716-446655440099';
|
||||
$handler(new ConfigureGradingModeCommand(
|
||||
tenantId: $otherTenantId,
|
||||
schoolId: self::SCHOOL_ID,
|
||||
academicYearId: self::ACADEMIC_YEAR_ID,
|
||||
gradingMode: 'competencies',
|
||||
));
|
||||
|
||||
$config1 = $this->repository->findBySchoolAndYear(
|
||||
TenantId::fromString(self::TENANT_ID),
|
||||
SchoolId::fromString(self::SCHOOL_ID),
|
||||
AcademicYearId::fromString(self::ACADEMIC_YEAR_ID),
|
||||
);
|
||||
|
||||
$config2 = $this->repository->findBySchoolAndYear(
|
||||
TenantId::fromString($otherTenantId),
|
||||
SchoolId::fromString(self::SCHOOL_ID),
|
||||
AcademicYearId::fromString(self::ACADEMIC_YEAR_ID),
|
||||
);
|
||||
|
||||
self::assertNotNull($config1);
|
||||
self::assertNotNull($config2);
|
||||
self::assertSame(GradingMode::NUMERIC_20, $config1->gradingConfiguration->mode);
|
||||
self::assertSame(GradingMode::COMPETENCIES, $config2->gradingConfiguration->mode);
|
||||
}
|
||||
|
||||
private function createHandler(bool $hasGrades): ConfigureGradingModeHandler
|
||||
{
|
||||
$gradeChecker = new class($hasGrades) implements GradeExistenceChecker {
|
||||
public function __construct(private bool $hasGrades)
|
||||
{
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function hasGradesInPeriod(TenantId $tenantId, AcademicYearId $academicYearId, int $periodSequence): bool
|
||||
{
|
||||
return $this->hasGrades;
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function hasGradesForYear(TenantId $tenantId, SchoolId $schoolId, AcademicYearId $academicYearId): bool
|
||||
{
|
||||
return $this->hasGrades;
|
||||
}
|
||||
};
|
||||
|
||||
return new ConfigureGradingModeHandler(
|
||||
$this->repository,
|
||||
$gradeChecker,
|
||||
$this->clock,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ use App\Administration\Domain\Exception\PeriodsOverlapException;
|
||||
use App\Administration\Domain\Model\AcademicYear\DefaultPeriods;
|
||||
use App\Administration\Domain\Model\AcademicYear\PeriodType;
|
||||
use App\Administration\Domain\Model\SchoolClass\AcademicYearId;
|
||||
use App\Administration\Domain\Model\SchoolClass\SchoolId;
|
||||
use App\Administration\Infrastructure\Persistence\InMemory\InMemoryPeriodConfigurationRepository;
|
||||
use App\Administration\Infrastructure\Service\NoOpGradeExistenceChecker;
|
||||
use App\Shared\Domain\Clock;
|
||||
@@ -54,7 +55,7 @@ final class UpdatePeriodHandlerTest extends TestCase
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function itUpdatesPeriodDates(): void
|
||||
public function itRejectsOverlappingPeriodDates(): void
|
||||
{
|
||||
$this->seedTrimesterConfig();
|
||||
|
||||
@@ -124,13 +125,7 @@ final class UpdatePeriodHandlerTest extends TestCase
|
||||
{
|
||||
$this->seedTrimesterConfig();
|
||||
|
||||
$gradeChecker = new class implements GradeExistenceChecker {
|
||||
#[Override]
|
||||
public function hasGradesInPeriod(TenantId $tenantId, AcademicYearId $academicYearId, int $periodSequence): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
$gradeChecker = $this->createGradeCheckerWithGrades();
|
||||
|
||||
$handler = new UpdatePeriodHandler($this->repository, $gradeChecker, $this->clock, $this->eventBus);
|
||||
|
||||
@@ -150,13 +145,7 @@ final class UpdatePeriodHandlerTest extends TestCase
|
||||
{
|
||||
$this->seedTrimesterConfig();
|
||||
|
||||
$gradeChecker = new class implements GradeExistenceChecker {
|
||||
#[Override]
|
||||
public function hasGradesInPeriod(TenantId $tenantId, AcademicYearId $academicYearId, int $periodSequence): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
$gradeChecker = $this->createGradeCheckerWithGrades();
|
||||
|
||||
$handler = new UpdatePeriodHandler($this->repository, $gradeChecker, $this->clock, $this->eventBus);
|
||||
|
||||
@@ -172,6 +161,23 @@ final class UpdatePeriodHandlerTest extends TestCase
|
||||
self::assertSame('2025-09-02', $config->periods[0]->startDate->format('Y-m-d'));
|
||||
}
|
||||
|
||||
private function createGradeCheckerWithGrades(): GradeExistenceChecker
|
||||
{
|
||||
return new class implements GradeExistenceChecker {
|
||||
#[Override]
|
||||
public function hasGradesInPeriod(TenantId $tenantId, AcademicYearId $academicYearId, int $periodSequence): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function hasGradesForYear(TenantId $tenantId, SchoolId $schoolId, AcademicYearId $academicYearId): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private function seedTrimesterConfig(): void
|
||||
{
|
||||
$config = DefaultPeriods::forType(PeriodType::TRIMESTER, 2025);
|
||||
|
||||
Reference in New Issue
Block a user