feat: Permettre la création manuelle d'élèves et leur affectation aux classes

Les administrateurs et secrétaires avaient besoin de pouvoir inscrire un
élève en cours d'année sans passer par un import CSV. Cette fonctionnalité
pose aussi les fondations du modèle élève↔classe (ClassAssignment) qui
sera réutilisé par l'import CSV en masse (Story 3.1).

L'email est désormais optionnel pour les élèves : si fourni, une invitation
est envoyée (User::inviter) ; sinon l'élève est créé avec le statut
INSCRIT sans accès compte (User::inscrire). La création de l'utilisateur
et l'affectation à la classe sont atomiques (transaction DBAL).

Côté frontend, la page /admin/students offre liste paginée, recherche,
filtrage par classe, création via modale (avec détection de doublons
côté serveur), et changement de classe avec optimistic update.
This commit is contained in:
2026-02-23 19:12:21 +01:00
parent e5203097ef
commit 560b941821
49 changed files with 5184 additions and 65 deletions

View File

@@ -6,25 +6,36 @@ namespace App\Tests\Unit\Administration\Application\Query\HasStudentsInClass;
use App\Administration\Application\Query\HasStudentsInClass\HasStudentsInClassHandler;
use App\Administration\Application\Query\HasStudentsInClass\HasStudentsInClassQuery;
use App\Administration\Domain\Model\ClassAssignment\ClassAssignment;
use App\Administration\Domain\Model\SchoolClass\AcademicYearId;
use App\Administration\Domain\Model\SchoolClass\ClassId;
use App\Administration\Domain\Model\User\UserId;
use App\Administration\Infrastructure\Persistence\InMemory\InMemoryClassAssignmentRepository;
use App\Shared\Domain\Tenant\TenantId;
use DateTimeImmutable;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
/**
* Tests for HasStudentsInClassHandler.
*
* Currently returns 0 (stub) until the student module is available.
* These tests document the expected behavior for when the implementation
* is completed.
*/
final class HasStudentsInClassHandlerTest extends TestCase
{
#[Test]
public function returnsZeroForAnyClass(): void
private const string TENANT_ID = '550e8400-e29b-41d4-a716-446655440001';
private const string CLASS_ID = '550e8400-e29b-41d4-a716-446655440020';
private const string ACADEMIC_YEAR_ID = '550e8400-e29b-41d4-a716-446655440040';
private InMemoryClassAssignmentRepository $repository;
protected function setUp(): void
{
$handler = new HasStudentsInClassHandler();
$this->repository = new InMemoryClassAssignmentRepository();
}
#[Test]
public function returnsZeroWhenNoStudentsAssigned(): void
{
$handler = new HasStudentsInClassHandler($this->repository);
$query = new HasStudentsInClassQuery(
classId: '550e8400-e29b-41d4-a716-446655440020',
classId: self::CLASS_ID,
);
$result = ($handler)($query);
@@ -33,28 +44,41 @@ final class HasStudentsInClassHandlerTest extends TestCase
}
#[Test]
public function returnsIntegerType(): void
public function returnsCountOfAssignedStudents(): void
{
$handler = new HasStudentsInClassHandler();
$this->addAssignment('550e8400-e29b-41d4-a716-446655440010');
$this->addAssignment('550e8400-e29b-41d4-a716-446655440011');
$query = new HasStudentsInClassQuery(
classId: '550e8400-e29b-41d4-a716-446655440021',
);
$handler = new HasStudentsInClassHandler($this->repository);
$result = ($handler)($query);
$result = ($handler)(new HasStudentsInClassQuery(classId: self::CLASS_ID));
self::assertIsInt($result);
self::assertSame(2, $result);
}
#[Test]
public function isConsistentAcrossMultipleCalls(): void
{
$handler = new HasStudentsInClassHandler();
$classId = '550e8400-e29b-41d4-a716-446655440022';
$this->addAssignment('550e8400-e29b-41d4-a716-446655440010');
$result1 = ($handler)(new HasStudentsInClassQuery(classId: $classId));
$result2 = ($handler)(new HasStudentsInClassQuery(classId: $classId));
$handler = new HasStudentsInClassHandler($this->repository);
$result1 = ($handler)(new HasStudentsInClassQuery(classId: self::CLASS_ID));
$result2 = ($handler)(new HasStudentsInClassQuery(classId: self::CLASS_ID));
self::assertSame($result1, $result2);
self::assertSame(1, $result1);
}
private function addAssignment(string $studentId): void
{
$assignment = ClassAssignment::affecter(
tenantId: TenantId::fromString(self::TENANT_ID),
studentId: UserId::fromString($studentId),
classId: ClassId::fromString(self::CLASS_ID),
academicYearId: AcademicYearId::fromString(self::ACADEMIC_YEAR_ID),
assignedAt: new DateTimeImmutable('2026-02-21 10:00:00'),
);
$this->repository->save($assignment);
}
}