Files
Classeo/backend/tests/Unit/SuperAdmin/Infrastructure/Api/Provider/EstablishmentCollectionProviderTest.php
Mathias STRASSER 3575d095a1
Some checks failed
CI / Backend Tests (push) Has been cancelled
CI / Frontend Tests (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
CI / Naming Conventions (push) Has been cancelled
CI / Build Check (push) Has been cancelled
feat: Provisionner automatiquement un nouvel établissement
Lorsqu'un super-admin crée un établissement via l'interface, le système
doit automatiquement créer la base tenant, exécuter les migrations,
créer le premier utilisateur admin et envoyer l'invitation — le tout
de manière asynchrone pour ne pas bloquer la réponse HTTP.

Ce mécanisme rend chaque établissement opérationnel dès sa création
sans intervention manuelle sur l'infrastructure.
2026-04-11 20:41:55 +02:00

56 lines
2.0 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Tests\Unit\SuperAdmin\Infrastructure\Api\Provider;
use ApiPlatform\Metadata\GetCollection;
use App\SuperAdmin\Application\Query\GetEstablishments\GetEstablishmentsHandler;
use App\SuperAdmin\Domain\Model\Establishment\Establishment;
use App\SuperAdmin\Domain\Model\SuperAdmin\SuperAdminId;
use App\SuperAdmin\Infrastructure\Api\Provider\EstablishmentCollectionProvider;
use App\SuperAdmin\Infrastructure\Persistence\InMemory\InMemoryEstablishmentRepository;
use DateTimeImmutable;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
final class EstablishmentCollectionProviderTest extends TestCase
{
private const string SUPER_ADMIN_ID = '550e8400-e29b-41d4-a716-446655440001';
#[Test]
public function provideReturnsEmptyArrayWhenNoEstablishments(): void
{
$repository = new InMemoryEstablishmentRepository();
$handler = new GetEstablishmentsHandler($repository);
$provider = new EstablishmentCollectionProvider($handler);
$result = $provider->provide(new GetCollection());
self::assertSame([], $result);
}
#[Test]
public function provideReturnsMappedResources(): void
{
$repository = new InMemoryEstablishmentRepository();
$repository->save(Establishment::creer(
name: 'École Alpha',
subdomain: 'ecole-alpha',
adminEmail: 'admin@ecole-alpha.fr',
createdBy: SuperAdminId::fromString(self::SUPER_ADMIN_ID),
createdAt: new DateTimeImmutable('2026-02-16 10:00:00'),
));
$handler = new GetEstablishmentsHandler($repository);
$provider = new EstablishmentCollectionProvider($handler);
$result = $provider->provide(new GetCollection());
self::assertCount(1, $result);
self::assertSame('École Alpha', $result[0]->name);
self::assertSame('ecole-alpha', $result[0]->subdomain);
self::assertSame('provisioning', $result[0]->status);
}
}