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:
2026-02-07 01:06:55 +01:00
parent f19d0ae3ef
commit ff18850a43
51 changed files with 3963 additions and 79 deletions

View File

@@ -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,
);
}
}

View File

@@ -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);

View File

@@ -0,0 +1,71 @@
<?php
declare(strict_types=1);
namespace App\Tests\Unit\Administration\Application\Query\HasGradesForYear;
use App\Administration\Application\Port\GradeExistenceChecker;
use App\Administration\Application\Query\HasGradesForYear\HasGradesForYearHandler;
use App\Administration\Application\Query\HasGradesForYear\HasGradesForYearQuery;
use App\Administration\Domain\Model\SchoolClass\AcademicYearId;
use App\Administration\Domain\Model\SchoolClass\SchoolId;
use App\Shared\Domain\Tenant\TenantId;
use Override;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
final class HasGradesForYearHandlerTest 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';
#[Test]
public function itReturnsFalseWhenNoGradesExist(): void
{
$handler = new HasGradesForYearHandler($this->createChecker(hasGrades: false));
$result = $handler(new HasGradesForYearQuery(
tenantId: self::TENANT_ID,
schoolId: self::SCHOOL_ID,
academicYearId: self::ACADEMIC_YEAR_ID,
));
self::assertFalse($result);
}
#[Test]
public function itReturnsTrueWhenGradesExist(): void
{
$handler = new HasGradesForYearHandler($this->createChecker(hasGrades: true));
$result = $handler(new HasGradesForYearQuery(
tenantId: self::TENANT_ID,
schoolId: self::SCHOOL_ID,
academicYearId: self::ACADEMIC_YEAR_ID,
));
self::assertTrue($result);
}
private function createChecker(bool $hasGrades): GradeExistenceChecker
{
return 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;
}
};
}
}

View File

@@ -0,0 +1,79 @@
<?php
declare(strict_types=1);
namespace App\Tests\Unit\Administration\Domain\Model\GradingConfiguration;
use App\Administration\Domain\Model\GradingConfiguration\GradingConfiguration;
use App\Administration\Domain\Model\GradingConfiguration\GradingMode;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
final class GradingConfigurationTest extends TestCase
{
#[Test]
public function itCreatesNumeric20Configuration(): void
{
$config = new GradingConfiguration(GradingMode::NUMERIC_20);
self::assertSame(GradingMode::NUMERIC_20, $config->mode);
}
#[Test]
public function itCreatesCompetenciesConfiguration(): void
{
$config = new GradingConfiguration(GradingMode::COMPETENCIES);
self::assertSame(GradingMode::COMPETENCIES, $config->mode);
}
#[Test]
public function itCreatesNoGradesConfiguration(): void
{
$config = new GradingConfiguration(GradingMode::NO_GRADES);
self::assertSame(GradingMode::NO_GRADES, $config->mode);
}
#[Test]
public function equalConfigurationsAreEqual(): void
{
$config1 = new GradingConfiguration(GradingMode::NUMERIC_20);
$config2 = new GradingConfiguration(GradingMode::NUMERIC_20);
self::assertTrue($config1->equals($config2));
}
#[Test]
public function differentConfigurationsAreNotEqual(): void
{
$config1 = new GradingConfiguration(GradingMode::NUMERIC_20);
$config2 = new GradingConfiguration(GradingMode::COMPETENCIES);
self::assertFalse($config1->equals($config2));
}
#[Test]
public function itDelegatesToModeForScaleMax(): void
{
$config = new GradingConfiguration(GradingMode::NUMERIC_20);
self::assertSame(20, $config->scaleMax());
$config = new GradingConfiguration(GradingMode::COMPETENCIES);
self::assertNull($config->scaleMax());
}
#[Test]
public function itDelegatesToModeForEstNumerique(): void
{
self::assertTrue((new GradingConfiguration(GradingMode::NUMERIC_20))->estNumerique());
self::assertFalse((new GradingConfiguration(GradingMode::NO_GRADES))->estNumerique());
}
#[Test]
public function itDelegatesToModeForCalculeMoyenne(): void
{
self::assertTrue((new GradingConfiguration(GradingMode::NUMERIC_20))->calculeMoyenne());
self::assertFalse((new GradingConfiguration(GradingMode::COMPETENCIES))->calculeMoyenne());
}
}

View File

@@ -0,0 +1,97 @@
<?php
declare(strict_types=1);
namespace App\Tests\Unit\Administration\Domain\Model\GradingConfiguration;
use App\Administration\Domain\Model\GradingConfiguration\GradingMode;
use App\Scolarite\Domain\Model\GradingMode as ScolariteGradingMode;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
final class GradingModeTest extends TestCase
{
#[Test]
public function itHasCorrectValues(): void
{
self::assertSame('numeric_20', GradingMode::NUMERIC_20->value);
self::assertSame('numeric_10', GradingMode::NUMERIC_10->value);
self::assertSame('letters', GradingMode::LETTERS->value);
self::assertSame('competencies', GradingMode::COMPETENCIES->value);
self::assertSame('no_grades', GradingMode::NO_GRADES->value);
}
#[Test]
public function numeric20HasCorrectScale(): void
{
self::assertSame(20, GradingMode::NUMERIC_20->scaleMax());
}
#[Test]
public function numeric10HasCorrectScale(): void
{
self::assertSame(10, GradingMode::NUMERIC_10->scaleMax());
}
#[Test]
public function nonNumericModesHaveNullScale(): void
{
self::assertNull(GradingMode::LETTERS->scaleMax());
self::assertNull(GradingMode::COMPETENCIES->scaleMax());
self::assertNull(GradingMode::NO_GRADES->scaleMax());
}
#[Test]
public function numericModesUseNumericGrading(): void
{
self::assertTrue(GradingMode::NUMERIC_20->estNumerique());
self::assertTrue(GradingMode::NUMERIC_10->estNumerique());
}
#[Test]
public function nonNumericModesDoNotUseNumericGrading(): void
{
self::assertFalse(GradingMode::LETTERS->estNumerique());
self::assertFalse(GradingMode::COMPETENCIES->estNumerique());
self::assertFalse(GradingMode::NO_GRADES->estNumerique());
}
#[Test]
public function modesRequiringAverageCalculation(): void
{
self::assertTrue(GradingMode::NUMERIC_20->calculeMoyenne());
self::assertTrue(GradingMode::NUMERIC_10->calculeMoyenne());
self::assertTrue(GradingMode::LETTERS->calculeMoyenne());
self::assertFalse(GradingMode::COMPETENCIES->calculeMoyenne());
self::assertFalse(GradingMode::NO_GRADES->calculeMoyenne());
}
#[Test]
public function labelsAreInFrench(): void
{
self::assertSame('Notes /20', GradingMode::NUMERIC_20->label());
self::assertSame('Notes /10', GradingMode::NUMERIC_10->label());
self::assertSame('Lettres (A-E)', GradingMode::LETTERS->label());
self::assertSame('Compétences', GradingMode::COMPETENCIES->label());
self::assertSame('Sans notes', GradingMode::NO_GRADES->label());
}
#[Test]
public function administrationAndScolariteEnumsAreInSync(): void
{
$adminValues = array_map(
static fn (GradingMode $m) => $m->value,
GradingMode::cases(),
);
$scolariteValues = array_map(
static fn (ScolariteGradingMode $m) => $m->value,
ScolariteGradingMode::cases(),
);
self::assertSame(
$adminValues,
$scolariteValues,
'Les enums GradingMode des contextes Administration et Scolarité doivent rester synchronisées.',
);
}
}

View File

@@ -0,0 +1,186 @@
<?php
declare(strict_types=1);
namespace App\Tests\Unit\Administration\Domain\Model\GradingConfiguration;
use App\Administration\Domain\Exception\CannotChangeGradingModeWithExistingGradesException;
use App\Administration\Domain\Model\GradingConfiguration\GradingConfiguration;
use App\Administration\Domain\Model\GradingConfiguration\GradingMode;
use App\Administration\Domain\Model\GradingConfiguration\SchoolGradingConfiguration;
use App\Administration\Domain\Model\SchoolClass\AcademicYearId;
use App\Administration\Domain\Model\SchoolClass\SchoolId;
use App\Shared\Domain\Tenant\TenantId;
use DateTimeImmutable;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
final class SchoolGradingConfigurationTest extends TestCase
{
private TenantId $tenantId;
private SchoolId $schoolId;
private AcademicYearId $academicYearId;
protected function setUp(): void
{
$this->tenantId = TenantId::generate();
$this->schoolId = SchoolId::generate();
$this->academicYearId = AcademicYearId::generate();
}
#[Test]
public function itConfiguresGradingMode(): void
{
$config = SchoolGradingConfiguration::configurer(
tenantId: $this->tenantId,
schoolId: $this->schoolId,
academicYearId: $this->academicYearId,
mode: GradingMode::NUMERIC_20,
hasExistingGrades: false,
configuredAt: new DateTimeImmutable('2026-02-01'),
);
self::assertSame(GradingMode::NUMERIC_20, $config->gradingConfiguration->mode);
self::assertSame($this->tenantId, $config->tenantId);
self::assertSame($this->schoolId, $config->schoolId);
self::assertSame($this->academicYearId, $config->academicYearId);
}
#[Test]
public function itEmitsEventOnCreation(): void
{
$config = SchoolGradingConfiguration::configurer(
tenantId: $this->tenantId,
schoolId: $this->schoolId,
academicYearId: $this->academicYearId,
mode: GradingMode::COMPETENCIES,
hasExistingGrades: false,
configuredAt: new DateTimeImmutable('2026-02-01'),
);
$events = $config->pullDomainEvents();
self::assertCount(1, $events);
}
#[Test]
public function itChangesGradingModeWhenNoGradesExist(): void
{
$config = SchoolGradingConfiguration::configurer(
tenantId: $this->tenantId,
schoolId: $this->schoolId,
academicYearId: $this->academicYearId,
mode: GradingMode::NUMERIC_20,
hasExistingGrades: false,
configuredAt: new DateTimeImmutable('2026-02-01'),
);
$config->pullDomainEvents();
$config->changerMode(
nouveauMode: GradingMode::COMPETENCIES,
hasExistingGrades: false,
at: new DateTimeImmutable('2026-02-02'),
);
self::assertSame(GradingMode::COMPETENCIES, $config->gradingConfiguration->mode);
$events = $config->pullDomainEvents();
self::assertCount(1, $events);
}
#[Test]
public function itBlocksChangeWhenGradesExist(): void
{
$config = SchoolGradingConfiguration::configurer(
tenantId: $this->tenantId,
schoolId: $this->schoolId,
academicYearId: $this->academicYearId,
mode: GradingMode::NUMERIC_20,
hasExistingGrades: false,
configuredAt: new DateTimeImmutable('2026-02-01'),
);
$this->expectException(CannotChangeGradingModeWithExistingGradesException::class);
$config->changerMode(
nouveauMode: GradingMode::COMPETENCIES,
hasExistingGrades: true,
at: new DateTimeImmutable('2026-02-02'),
);
}
#[Test]
public function itDoesNotEmitEventWhenModeIsUnchanged(): void
{
$config = SchoolGradingConfiguration::configurer(
tenantId: $this->tenantId,
schoolId: $this->schoolId,
academicYearId: $this->academicYearId,
mode: GradingMode::NUMERIC_20,
hasExistingGrades: false,
configuredAt: new DateTimeImmutable('2026-02-01'),
);
$config->pullDomainEvents();
$config->changerMode(
nouveauMode: GradingMode::NUMERIC_20,
hasExistingGrades: false,
at: new DateTimeImmutable('2026-02-02'),
);
self::assertEmpty($config->pullDomainEvents());
}
#[Test]
public function itReconstitutesFromStorage(): void
{
$id = SchoolGradingConfiguration::generateId();
$config = SchoolGradingConfiguration::reconstitute(
id: $id,
tenantId: $this->tenantId,
schoolId: $this->schoolId,
academicYearId: $this->academicYearId,
gradingConfiguration: new GradingConfiguration(GradingMode::LETTERS),
configuredAt: new DateTimeImmutable('2026-02-01'),
updatedAt: new DateTimeImmutable('2026-02-02'),
);
self::assertSame(GradingMode::LETTERS, $config->gradingConfiguration->mode);
self::assertEmpty($config->pullDomainEvents());
}
#[Test]
public function itBlocksInitialNonDefaultModeWhenGradesExist(): void
{
$this->expectException(CannotChangeGradingModeWithExistingGradesException::class);
SchoolGradingConfiguration::configurer(
tenantId: $this->tenantId,
schoolId: $this->schoolId,
academicYearId: $this->academicYearId,
mode: GradingMode::COMPETENCIES,
hasExistingGrades: true,
configuredAt: new DateTimeImmutable('2026-02-01'),
);
}
#[Test]
public function itAllowsInitialDefaultModeWhenGradesExist(): void
{
$config = SchoolGradingConfiguration::configurer(
tenantId: $this->tenantId,
schoolId: $this->schoolId,
academicYearId: $this->academicYearId,
mode: GradingMode::NUMERIC_20,
hasExistingGrades: true,
configuredAt: new DateTimeImmutable('2026-02-01'),
);
self::assertSame(GradingMode::NUMERIC_20, $config->gradingConfiguration->mode);
}
#[Test]
public function defaultModeIsNumeric20(): void
{
self::assertSame(GradingMode::NUMERIC_20, SchoolGradingConfiguration::DEFAULT_MODE);
}
}

View File

@@ -0,0 +1,254 @@
<?php
declare(strict_types=1);
namespace App\Tests\Unit\Administration\Infrastructure\Api\Processor;
use ApiPlatform\Metadata\Put;
use App\Administration\Application\Command\ConfigureGradingMode\ConfigureGradingModeHandler;
use App\Administration\Application\Port\GradeExistenceChecker;
use App\Administration\Domain\Model\SchoolClass\AcademicYearId;
use App\Administration\Domain\Model\SchoolClass\SchoolId;
use App\Administration\Infrastructure\Api\Processor\ConfigureGradingModeProcessor;
use App\Administration\Infrastructure\Api\Resource\GradingModeResource;
use App\Administration\Infrastructure\Persistence\InMemory\InMemoryGradingConfigurationRepository;
use App\Administration\Infrastructure\School\SchoolIdResolver;
use App\Administration\Infrastructure\Service\CurrentAcademicYearResolver;
use App\Shared\Domain\Clock;
use App\Shared\Domain\Tenant\TenantId;
use App\Shared\Infrastructure\Tenant\TenantConfig;
use App\Shared\Infrastructure\Tenant\TenantContext;
use App\Shared\Infrastructure\Tenant\TenantId as InfraTenantId;
use DateTimeImmutable;
use Override;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\Exception\ConflictHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Security\Core\Authorization\AccessDecision;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
final class ConfigureGradingModeProcessorTest extends TestCase
{
private const string TENANT_UUID = '550e8400-e29b-41d4-a716-446655440001';
private InMemoryGradingConfigurationRepository $repository;
private TenantContext $tenantContext;
private Clock $clock;
protected function setUp(): void
{
$this->repository = new InMemoryGradingConfigurationRepository();
$this->tenantContext = new TenantContext();
$this->clock = new class implements Clock {
#[Override]
public function now(): DateTimeImmutable
{
return new DateTimeImmutable('2025-10-15 10:00:00');
}
};
}
#[Test]
public function itRejectsUnauthorizedAccess(): void
{
$processor = $this->createProcessor(granted: false);
$this->setTenant();
$data = new GradingModeResource();
$data->mode = 'numeric_20';
$this->expectException(AccessDeniedHttpException::class);
$processor->process($data, new Put(), ['academicYearId' => 'current']);
}
#[Test]
public function itRejectsRequestWithoutTenant(): void
{
$processor = $this->createProcessor(granted: true);
$data = new GradingModeResource();
$data->mode = 'numeric_20';
$this->expectException(UnauthorizedHttpException::class);
$processor->process($data, new Put(), ['academicYearId' => 'current']);
}
#[Test]
public function itRejectsInvalidAcademicYearId(): void
{
$processor = $this->createProcessor(granted: true);
$this->setTenant();
$data = new GradingModeResource();
$data->mode = 'numeric_20';
$this->expectException(NotFoundHttpException::class);
$processor->process($data, new Put(), ['academicYearId' => 'invalid']);
}
#[Test]
public function itConfiguresGradingMode(): void
{
$processor = $this->createProcessor(granted: true);
$this->setTenant();
$data = new GradingModeResource();
$data->mode = 'competencies';
$result = $processor->process($data, new Put(), ['academicYearId' => 'current']);
self::assertInstanceOf(GradingModeResource::class, $result);
self::assertSame('competencies', $result->mode);
self::assertSame('Compétences', $result->label);
self::assertFalse($result->hasExistingGrades);
}
#[Test]
public function itSetsAvailableModesOnResult(): void
{
$processor = $this->createProcessor(granted: true);
$this->setTenant();
$data = new GradingModeResource();
$data->mode = 'numeric_20';
$result = $processor->process($data, new Put(), ['academicYearId' => 'current']);
self::assertNotNull($result->availableModes);
self::assertCount(5, $result->availableModes);
}
#[Test]
public function itThrowsConflictWhenGradesExistAndModeChanges(): void
{
// First configure with numeric_20 (no grades)
$processor = $this->createProcessor(granted: true, hasGrades: false);
$this->setTenant();
$data = new GradingModeResource();
$data->mode = 'numeric_20';
$processor->process($data, new Put(), ['academicYearId' => 'current']);
// Now try to change mode with grades existing
$processorWithGrades = $this->createProcessor(granted: true, hasGrades: true);
$this->setTenant();
$data = new GradingModeResource();
$data->mode = 'competencies';
$this->expectException(ConflictHttpException::class);
$processorWithGrades->process($data, new Put(), ['academicYearId' => 'current']);
}
#[Test]
public function itChangesExistingModeWhenNoGradesExist(): void
{
$processor = $this->createProcessor(granted: true);
$this->setTenant();
$data = new GradingModeResource();
$data->mode = 'numeric_20';
$processor->process($data, new Put(), ['academicYearId' => 'current']);
$data = new GradingModeResource();
$data->mode = 'letters';
$result = $processor->process($data, new Put(), ['academicYearId' => 'current']);
self::assertSame('letters', $result->mode);
}
#[Test]
public function itResolvesNextAcademicYear(): void
{
$processor = $this->createProcessor(granted: true);
$this->setTenant();
$data = new GradingModeResource();
$data->mode = 'no_grades';
$result = $processor->process($data, new Put(), ['academicYearId' => 'next']);
self::assertSame('no_grades', $result->mode);
}
#[Test]
public function itRejectsInvalidGradingModeWithBadRequest(): void
{
$processor = $this->createProcessor(granted: true);
$this->setTenant();
$data = new GradingModeResource();
$data->mode = 'invalid_mode';
$this->expectException(BadRequestHttpException::class);
$processor->process($data, new Put(), ['academicYearId' => 'current']);
}
private function setTenant(): void
{
$this->tenantContext->setCurrentTenant(new TenantConfig(
tenantId: InfraTenantId::fromString(self::TENANT_UUID),
subdomain: 'test',
databaseUrl: 'sqlite:///:memory:',
));
}
private function createProcessor(bool $granted, bool $hasGrades = false): ConfigureGradingModeProcessor
{
$authChecker = new class($granted) implements AuthorizationCheckerInterface {
public function __construct(private readonly bool $granted)
{
}
public function isGranted(mixed $attribute, mixed $subject = null, ?AccessDecision $accessDecision = null): bool
{
return $this->granted;
}
};
$eventBus = new class implements MessageBusInterface {
public function dispatch(object $message, array $stamps = []): Envelope
{
return new Envelope($message);
}
};
$gradeChecker = new class($hasGrades) implements GradeExistenceChecker {
public function __construct(private readonly 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;
}
};
$handler = new ConfigureGradingModeHandler($this->repository, $gradeChecker, $this->clock);
$resolver = new CurrentAcademicYearResolver($this->tenantContext, $this->clock);
$schoolIdResolver = new SchoolIdResolver();
return new ConfigureGradingModeProcessor(
$handler,
$gradeChecker,
$this->tenantContext,
$eventBus,
$authChecker,
$resolver,
$schoolIdResolver,
);
}
}

View File

@@ -0,0 +1,226 @@
<?php
declare(strict_types=1);
namespace App\Tests\Unit\Administration\Infrastructure\Api\Provider;
use ApiPlatform\Metadata\Get;
use App\Administration\Application\Port\GradeExistenceChecker;
use App\Administration\Domain\Model\GradingConfiguration\GradingMode;
use App\Administration\Domain\Model\GradingConfiguration\SchoolGradingConfiguration;
use App\Administration\Domain\Model\SchoolClass\AcademicYearId;
use App\Administration\Domain\Model\SchoolClass\SchoolId;
use App\Administration\Infrastructure\Api\Provider\GradingModeProvider;
use App\Administration\Infrastructure\Api\Resource\GradingModeResource;
use App\Administration\Infrastructure\Persistence\InMemory\InMemoryGradingConfigurationRepository;
use App\Administration\Infrastructure\School\SchoolIdResolver;
use App\Administration\Infrastructure\Service\CurrentAcademicYearResolver;
use App\Shared\Domain\Clock;
use App\Shared\Domain\Tenant\TenantId;
use App\Shared\Infrastructure\Tenant\TenantConfig;
use App\Shared\Infrastructure\Tenant\TenantContext;
use App\Shared\Infrastructure\Tenant\TenantId as InfraTenantId;
use DateTimeImmutable;
use Override;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
use Symfony\Component\Security\Core\Authorization\AccessDecision;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
final class GradingModeProviderTest extends TestCase
{
private const string TENANT_UUID = '550e8400-e29b-41d4-a716-446655440001';
private InMemoryGradingConfigurationRepository $repository;
private TenantContext $tenantContext;
private Clock $clock;
protected function setUp(): void
{
$this->repository = new InMemoryGradingConfigurationRepository();
$this->tenantContext = new TenantContext();
$this->clock = new class implements Clock {
#[Override]
public function now(): DateTimeImmutable
{
return new DateTimeImmutable('2025-10-15 10:00:00');
}
};
}
#[Test]
public function itRejectsUnauthorizedAccess(): void
{
$provider = $this->createProvider(granted: false);
$this->setTenant();
$this->expectException(AccessDeniedHttpException::class);
$provider->provide(new Get(), ['academicYearId' => 'current']);
}
#[Test]
public function itRejectsRequestWithoutTenant(): void
{
$provider = $this->createProvider(granted: true);
$this->expectException(UnauthorizedHttpException::class);
$provider->provide(new Get(), ['academicYearId' => 'current']);
}
#[Test]
public function itRejectsInvalidAcademicYearId(): void
{
$provider = $this->createProvider(granted: true);
$this->setTenant();
$this->expectException(NotFoundHttpException::class);
$provider->provide(new Get(), ['academicYearId' => 'invalid']);
}
#[Test]
public function itReturnsDefaultModeWhenNoConfigurationExists(): void
{
$provider = $this->createProvider(granted: true);
$this->setTenant();
$result = $provider->provide(new Get(), ['academicYearId' => 'current']);
self::assertInstanceOf(GradingModeResource::class, $result);
self::assertSame('numeric_20', $result->mode);
self::assertSame('Notes /20', $result->label);
self::assertFalse($result->hasExistingGrades);
}
#[Test]
public function itReturnsExistingConfigurationWhenPresent(): void
{
$provider = $this->createProvider(granted: true);
$this->setTenant();
$resolver = new CurrentAcademicYearResolver($this->tenantContext, $this->clock);
$academicYearId = $resolver->resolve('current');
self::assertNotNull($academicYearId);
$schoolIdResolver = new SchoolIdResolver();
$schoolId = $schoolIdResolver->resolveForTenant(self::TENANT_UUID);
$config = SchoolGradingConfiguration::configurer(
tenantId: TenantId::fromString(self::TENANT_UUID),
schoolId: SchoolId::fromString($schoolId),
academicYearId: AcademicYearId::fromString($academicYearId),
mode: GradingMode::COMPETENCIES,
hasExistingGrades: false,
configuredAt: new DateTimeImmutable(),
);
$this->repository->save($config);
$result = $provider->provide(new Get(), ['academicYearId' => 'current']);
self::assertInstanceOf(GradingModeResource::class, $result);
self::assertSame('competencies', $result->mode);
self::assertSame('Compétences', $result->label);
}
#[Test]
public function itSetsAvailableModesOnResult(): void
{
$provider = $this->createProvider(granted: true);
$this->setTenant();
$result = $provider->provide(new Get(), ['academicYearId' => 'current']);
self::assertNotNull($result->availableModes);
self::assertCount(5, $result->availableModes);
}
#[Test]
public function itSetsHasExistingGradesFlag(): void
{
$provider = $this->createProvider(granted: true, hasGrades: true);
$this->setTenant();
$result = $provider->provide(new Get(), ['academicYearId' => 'current']);
self::assertTrue($result->hasExistingGrades);
}
#[Test]
public function itResolvesNextAcademicYear(): void
{
$provider = $this->createProvider(granted: true);
$this->setTenant();
$result = $provider->provide(new Get(), ['academicYearId' => 'next']);
self::assertInstanceOf(GradingModeResource::class, $result);
self::assertSame('numeric_20', $result->mode);
}
#[Test]
public function itResolvesPreviousAcademicYear(): void
{
$provider = $this->createProvider(granted: true);
$this->setTenant();
$result = $provider->provide(new Get(), ['academicYearId' => 'previous']);
self::assertInstanceOf(GradingModeResource::class, $result);
self::assertSame('numeric_20', $result->mode);
}
private function setTenant(): void
{
$this->tenantContext->setCurrentTenant(new TenantConfig(
tenantId: InfraTenantId::fromString(self::TENANT_UUID),
subdomain: 'test',
databaseUrl: 'sqlite:///:memory:',
));
}
private function createProvider(bool $granted, bool $hasGrades = false): GradingModeProvider
{
$authChecker = new class($granted) implements AuthorizationCheckerInterface {
public function __construct(private readonly bool $granted)
{
}
public function isGranted(mixed $attribute, mixed $subject = null, ?AccessDecision $accessDecision = null): bool
{
return $this->granted;
}
};
$gradeChecker = new class($hasGrades) implements GradeExistenceChecker {
public function __construct(private readonly 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;
}
};
$resolver = new CurrentAcademicYearResolver($this->tenantContext, $this->clock);
$schoolIdResolver = new SchoolIdResolver();
return new GradingModeProvider(
$this->repository,
$gradeChecker,
$this->tenantContext,
$authChecker,
$resolver,
$schoolIdResolver,
);
}
}

View File

@@ -0,0 +1,124 @@
<?php
declare(strict_types=1);
namespace App\Tests\Unit\Administration\Infrastructure\Api\Resource;
use App\Administration\Domain\Model\GradingConfiguration\GradingMode;
use App\Administration\Domain\Model\GradingConfiguration\SchoolGradingConfiguration;
use App\Administration\Domain\Model\SchoolClass\AcademicYearId;
use App\Administration\Domain\Model\SchoolClass\SchoolId;
use App\Administration\Infrastructure\Api\Resource\GradingModeResource;
use App\Shared\Domain\Tenant\TenantId;
use DateTimeImmutable;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
final class GradingModeResourceTest extends TestCase
{
#[Test]
public function fromDomainMapsAllFields(): void
{
$config = SchoolGradingConfiguration::configurer(
tenantId: TenantId::generate(),
schoolId: SchoolId::generate(),
academicYearId: AcademicYearId::generate(),
mode: GradingMode::NUMERIC_20,
hasExistingGrades: false,
configuredAt: new DateTimeImmutable(),
);
$resource = GradingModeResource::fromDomain($config);
self::assertSame('numeric_20', $resource->mode);
self::assertSame('Notes /20', $resource->label);
self::assertSame(20, $resource->scaleMax);
self::assertTrue($resource->isNumeric);
self::assertTrue($resource->calculatesAverage);
self::assertSame((string) $config->academicYearId, $resource->academicYearId);
}
#[Test]
public function fromDomainMapsCompetenciesMode(): void
{
$config = SchoolGradingConfiguration::configurer(
tenantId: TenantId::generate(),
schoolId: SchoolId::generate(),
academicYearId: AcademicYearId::generate(),
mode: GradingMode::COMPETENCIES,
hasExistingGrades: false,
configuredAt: new DateTimeImmutable(),
);
$resource = GradingModeResource::fromDomain($config);
self::assertSame('competencies', $resource->mode);
self::assertSame('Compétences', $resource->label);
self::assertNull($resource->scaleMax);
self::assertFalse($resource->isNumeric);
self::assertFalse($resource->calculatesAverage);
}
#[Test]
public function fromDomainMapsNoGradesMode(): void
{
$config = SchoolGradingConfiguration::configurer(
tenantId: TenantId::generate(),
schoolId: SchoolId::generate(),
academicYearId: AcademicYearId::generate(),
mode: GradingMode::NO_GRADES,
hasExistingGrades: false,
configuredAt: new DateTimeImmutable(),
);
$resource = GradingModeResource::fromDomain($config);
self::assertSame('no_grades', $resource->mode);
self::assertSame('Sans notes', $resource->label);
self::assertNull($resource->scaleMax);
self::assertFalse($resource->isNumeric);
self::assertFalse($resource->calculatesAverage);
}
#[Test]
public function defaultForYearUsesNumeric20(): void
{
$yearId = 'some-year-id';
$resource = GradingModeResource::defaultForYear($yearId);
self::assertSame($yearId, $resource->academicYearId);
self::assertSame('numeric_20', $resource->mode);
self::assertSame('Notes /20', $resource->label);
self::assertSame(20, $resource->scaleMax);
self::assertTrue($resource->isNumeric);
self::assertTrue($resource->calculatesAverage);
self::assertFalse($resource->hasExistingGrades);
}
#[Test]
public function allAvailableModesReturnsAllFiveModes(): void
{
$modes = GradingModeResource::allAvailableModes();
self::assertCount(5, $modes);
$values = array_column($modes, 'value');
self::assertContains('numeric_20', $values);
self::assertContains('numeric_10', $values);
self::assertContains('letters', $values);
self::assertContains('competencies', $values);
self::assertContains('no_grades', $values);
}
#[Test]
public function allAvailableModesContainsLabels(): void
{
$modes = GradingModeResource::allAvailableModes();
foreach ($modes as $mode) {
self::assertArrayHasKey('value', $mode);
self::assertArrayHasKey('label', $mode);
self::assertNotEmpty($mode['label']);
}
}
}

View File

@@ -0,0 +1,141 @@
<?php
declare(strict_types=1);
namespace App\Tests\Unit\Administration\Infrastructure\Security;
use App\Administration\Infrastructure\Security\GradingModeVoter;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\User\UserInterface;
final class GradingModeVoterTest extends TestCase
{
private GradingModeVoter $voter;
protected function setUp(): void
{
$this->voter = new GradingModeVoter();
}
#[Test]
public function itAbstainsForUnrelatedAttributes(): void
{
$user = $this->createMock(UserInterface::class);
$user->method('getRoles')->willReturn(['ROLE_ADMIN']);
$token = $this->createMock(TokenInterface::class);
$token->method('getUser')->willReturn($user);
$result = $this->voter->vote($token, null, ['SOME_OTHER_ATTRIBUTE']);
self::assertSame(GradingModeVoter::ACCESS_ABSTAIN, $result);
}
#[Test]
public function itDeniesAccessToUnauthenticatedUsers(): void
{
$token = $this->createMock(TokenInterface::class);
$token->method('getUser')->willReturn(null);
$result = $this->voter->vote($token, null, [GradingModeVoter::VIEW]);
self::assertSame(GradingModeVoter::ACCESS_DENIED, $result);
}
#[Test]
public function itGrantsViewToSuperAdmin(): void
{
$result = $this->voteWithRole('ROLE_SUPER_ADMIN', GradingModeVoter::VIEW);
self::assertSame(GradingModeVoter::ACCESS_GRANTED, $result);
}
#[Test]
public function itGrantsViewToAdmin(): void
{
$result = $this->voteWithRole('ROLE_ADMIN', GradingModeVoter::VIEW);
self::assertSame(GradingModeVoter::ACCESS_GRANTED, $result);
}
#[Test]
public function itGrantsViewToProf(): void
{
$result = $this->voteWithRole('ROLE_PROF', GradingModeVoter::VIEW);
self::assertSame(GradingModeVoter::ACCESS_GRANTED, $result);
}
#[Test]
public function itGrantsViewToVieScolaire(): void
{
$result = $this->voteWithRole('ROLE_VIE_SCOLAIRE', GradingModeVoter::VIEW);
self::assertSame(GradingModeVoter::ACCESS_GRANTED, $result);
}
#[Test]
public function itGrantsViewToSecretariat(): void
{
$result = $this->voteWithRole('ROLE_SECRETARIAT', GradingModeVoter::VIEW);
self::assertSame(GradingModeVoter::ACCESS_GRANTED, $result);
}
#[Test]
public function itDeniesViewToParent(): void
{
$result = $this->voteWithRole('ROLE_PARENT', GradingModeVoter::VIEW);
self::assertSame(GradingModeVoter::ACCESS_DENIED, $result);
}
#[Test]
public function itDeniesViewToEleve(): void
{
$result = $this->voteWithRole('ROLE_ELEVE', GradingModeVoter::VIEW);
self::assertSame(GradingModeVoter::ACCESS_DENIED, $result);
}
#[Test]
public function itGrantsConfigureToSuperAdmin(): void
{
$result = $this->voteWithRole('ROLE_SUPER_ADMIN', GradingModeVoter::CONFIGURE);
self::assertSame(GradingModeVoter::ACCESS_GRANTED, $result);
}
#[Test]
public function itGrantsConfigureToAdmin(): void
{
$result = $this->voteWithRole('ROLE_ADMIN', GradingModeVoter::CONFIGURE);
self::assertSame(GradingModeVoter::ACCESS_GRANTED, $result);
}
#[Test]
public function itDeniesConfigureToProf(): void
{
$result = $this->voteWithRole('ROLE_PROF', GradingModeVoter::CONFIGURE);
self::assertSame(GradingModeVoter::ACCESS_DENIED, $result);
}
#[Test]
public function itDeniesConfigureToVieScolaire(): void
{
$result = $this->voteWithRole('ROLE_VIE_SCOLAIRE', GradingModeVoter::CONFIGURE);
self::assertSame(GradingModeVoter::ACCESS_DENIED, $result);
}
#[Test]
public function itDeniesConfigureToSecretariat(): void
{
$result = $this->voteWithRole('ROLE_SECRETARIAT', GradingModeVoter::CONFIGURE);
self::assertSame(GradingModeVoter::ACCESS_DENIED, $result);
}
private function voteWithRole(string $role, string $attribute): int
{
$user = $this->createMock(UserInterface::class);
$user->method('getRoles')->willReturn([$role]);
$token = $this->createMock(TokenInterface::class);
$token->method('getUser')->willReturn($user);
return $this->voter->vote($token, null, [$attribute]);
}
}

View File

@@ -0,0 +1,93 @@
<?php
declare(strict_types=1);
namespace App\Tests\Unit\Scolarite\Domain\Service;
use App\Scolarite\Domain\Model\GradingMode;
use App\Scolarite\Domain\Service\SerenityScoreWeights;
use InvalidArgumentException;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
final class SerenityScoreWeightsTest extends TestCase
{
#[Test]
public function numericModeUsesStandardWeights(): void
{
$weights = SerenityScoreWeights::forMode(GradingMode::NUMERIC_20);
self::assertSame(0.4, $weights->notesWeight);
self::assertSame(0.3, $weights->absencesWeight);
self::assertSame(0.3, $weights->devoirsWeight);
}
#[Test]
public function competencyModeUsesAdaptedWeights(): void
{
$weights = SerenityScoreWeights::forMode(GradingMode::COMPETENCIES);
self::assertSame(0.4, $weights->notesWeight);
self::assertSame(0.3, $weights->absencesWeight);
self::assertSame(0.3, $weights->devoirsWeight);
}
#[Test]
public function noGradesModeExcludesNotesComponent(): void
{
$weights = SerenityScoreWeights::forMode(GradingMode::NO_GRADES);
self::assertSame(0.0, $weights->notesWeight);
self::assertSame(0.5, $weights->absencesWeight);
self::assertSame(0.5, $weights->devoirsWeight);
}
#[Test]
public function lettersModeUsesStandardWeights(): void
{
$weights = SerenityScoreWeights::forMode(GradingMode::LETTERS);
self::assertSame(0.4, $weights->notesWeight);
self::assertSame(0.3, $weights->absencesWeight);
self::assertSame(0.3, $weights->devoirsWeight);
}
#[Test]
public function weightsAlwaysSumToOne(): void
{
foreach (GradingMode::cases() as $mode) {
$weights = SerenityScoreWeights::forMode($mode);
$sum = $weights->notesWeight + $weights->absencesWeight + $weights->devoirsWeight;
self::assertEqualsWithDelta(1.0, $sum, 0.001, "Weights for {$mode->value} must sum to 1.0");
}
}
#[Test]
public function competencyMappingConvertsToPercentage(): void
{
$weights = SerenityScoreWeights::forMode(GradingMode::COMPETENCIES);
self::assertSame(100, $weights->competencyToScore('acquired'));
self::assertSame(50, $weights->competencyToScore('in_progress'));
self::assertSame(0, $weights->competencyToScore('not_acquired'));
}
#[Test]
public function nonCompetencyModesReturnNullForMapping(): void
{
$weights = SerenityScoreWeights::forMode(GradingMode::NUMERIC_20);
self::assertNull($weights->competencyToScore('acquired'));
}
#[Test]
public function competencyMappingThrowsOnUnknownLevel(): void
{
$weights = SerenityScoreWeights::forMode(GradingMode::COMPETENCIES);
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage("Niveau de compétence inconnu : 'unknown_level'");
$weights->competencyToScore('unknown_level');
}
}