test: ajout tests User, Revendeur, Service et ServiceCategory

tests/Entity/UserExtendedTest.php (8 nouveaux tests):
- testSetIsEmailAuthEnabled: active l'auth email, verifie true sans
  keycloakId et false avec keycloakId
- testSetIsGoogleAuthEnabled: active Google Auth + secret
- testClearTempPassword: verifie clearTempPassword() met hasTempPassword a false
- testGenerateBackupCodes: genere 5 codes, verifie le count
- testSerializeUnserialize: serialise/deserialise, verifie l'email
- testCreatedAt: verifie le type DateTimeImmutable
- testUpdatedAt: null par defaut
- testEraseCredentials: appel sans erreur

tests/Entity/RevendeurTest.php (nouveau, 10 tests):
- testConstructor: id null, codeRevendeur, user, createdAt, isActive
- testRaisonSociale: get/set nullable
- testSiret: get/set
- testAddress: address, zipCode, city
- testContact: email, phone
- testStripeConnect: stripeConnectId, isUseStripe
- testStripeConnectState: state, statePayment, statePayout
- testContratPdf: unsigned, signed, audit, submitterId
- testActive: setIsActive false
- testUpdatedAt: get/set nullable

tests/Entity/ServiceTest.php (nouveau, 12 tests):
- testConstructor: tous les champs par defaut
- testSetName, testSetUrl, testSetStatus (avec message)
- testExternal: isExternal, externalType
- testPosition: get/set
- testStatusHistory: collection vide
- testCategory: verifie la relation
- testComputeUptimeRatioAllUp: 2 entries up = 100%
- testComputeUptimeRatioMixed: ratio entre 0 et 100
- testComputeUptimeRatioEmpty: pas d'historique = 100%

tests/Entity/ServiceCategoryTest.php (nouveau, 3 tests):
- testConstructor: name, slug, position 0, createdAt, services vide
- testSetName: modification du nom
- testSetPosition: modification de la position

Resultat: 294 tests, 534 assertions, 0 failures, 0 deprecations, 0 notices

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Serreau Jovann
2026-04-02 23:57:05 +02:00
parent a4eb9f6e2d
commit c0b31fb93d
4 changed files with 339 additions and 0 deletions

View File

@@ -0,0 +1,127 @@
<?php
namespace App\Tests\Entity;
use App\Entity\Revendeur;
use App\Entity\User;
use PHPUnit\Framework\TestCase;
class RevendeurTest extends TestCase
{
private function createRevendeur(): Revendeur
{
$user = new User();
$user->setEmail('r@test.com');
$user->setFirstName('Jane');
$user->setLastName('Smith');
$user->setPassword('h');
return new Revendeur($user, 'SC-0001');
}
public function testConstructor(): void
{
$rev = $this->createRevendeur();
$this->assertNull($rev->getId());
$this->assertSame('SC-0001', $rev->getCodeRevendeur());
$this->assertSame('Jane', $rev->getUser()->getFirstName());
$this->assertInstanceOf(\DateTimeImmutable::class, $rev->getCreatedAt());
$this->assertTrue($rev->isActive());
}
public function testRaisonSociale(): void
{
$rev = $this->createRevendeur();
$this->assertNull($rev->getRaisonSociale());
$rev->setRaisonSociale('SARL Test');
$this->assertSame('SARL Test', $rev->getRaisonSociale());
}
public function testSiret(): void
{
$rev = $this->createRevendeur();
$rev->setSiret('12345678901234');
$this->assertSame('12345678901234', $rev->getSiret());
}
public function testAddress(): void
{
$rev = $this->createRevendeur();
$rev->setAddress('1 rue Test');
$rev->setZipCode('02100');
$rev->setCity('Saint-Quentin');
$this->assertSame('1 rue Test', $rev->getAddress());
$this->assertSame('02100', $rev->getZipCode());
$this->assertSame('Saint-Quentin', $rev->getCity());
}
public function testContact(): void
{
$rev = $this->createRevendeur();
$rev->setEmail('contact@test.fr');
$rev->setPhone('0612345678');
$this->assertSame('contact@test.fr', $rev->getEmail());
$this->assertSame('0612345678', $rev->getPhone());
}
public function testStripeConnect(): void
{
$rev = $this->createRevendeur();
$this->assertNull($rev->getStripeConnectId());
$this->assertFalse($rev->isUseStripe());
$rev->setStripeConnectId('acct_xxx');
$rev->setIsUseStripe(true);
$this->assertSame('acct_xxx', $rev->getStripeConnectId());
$this->assertTrue($rev->isUseStripe());
}
public function testStripeConnectState(): void
{
$rev = $this->createRevendeur();
$this->assertSame('not_started', $rev->getStripeConnectState());
$this->assertNull($rev->getStripeConnectStatePayment());
$this->assertNull($rev->getStripeConnectStatePayout());
$rev->setStripeConnectState('active');
$rev->setStripeConnectStatePayment('enabled');
$rev->setStripeConnectStatePayout('enabled');
$this->assertSame('active', $rev->getStripeConnectState());
$this->assertSame('enabled', $rev->getStripeConnectStatePayment());
$this->assertSame('enabled', $rev->getStripeConnectStatePayout());
}
public function testContratPdf(): void
{
$rev = $this->createRevendeur();
$this->assertNull($rev->getContratResellerPdfUnsigned());
$this->assertNull($rev->getContratResellerPdfSigned());
$this->assertNull($rev->getContratResellerPdfAudit());
$this->assertNull($rev->getContratSubmitterId());
$rev->setContratResellerPdfUnsigned('/path/unsigned.pdf');
$rev->setContratResellerPdfSigned('/path/signed.pdf');
$rev->setContratResellerPdfAudit('/path/audit.pdf');
$rev->setContratSubmitterId(42);
$this->assertSame('/path/unsigned.pdf', $rev->getContratResellerPdfUnsigned());
$this->assertSame('/path/signed.pdf', $rev->getContratResellerPdfSigned());
$this->assertSame('/path/audit.pdf', $rev->getContratResellerPdfAudit());
$this->assertSame(42, $rev->getContratSubmitterId());
}
public function testActive(): void
{
$rev = $this->createRevendeur();
$rev->setIsActive(false);
$this->assertFalse($rev->isActive());
}
public function testUpdatedAt(): void
{
$rev = $this->createRevendeur();
$this->assertNull($rev->getUpdatedAt());
$date = new \DateTimeImmutable();
$rev->setUpdatedAt($date);
$this->assertSame($date, $rev->getUpdatedAt());
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace App\Tests\Entity;
use App\Entity\ServiceCategory;
use PHPUnit\Framework\TestCase;
class ServiceCategoryTest extends TestCase
{
public function testConstructor(): void
{
$cat = new ServiceCategory('Infrastructure', 'infra');
$this->assertNull($cat->getId());
$this->assertSame('Infrastructure', $cat->getName());
$this->assertSame('infra', $cat->getSlug());
$this->assertSame(0, $cat->getPosition());
$this->assertInstanceOf(\DateTimeImmutable::class, $cat->getCreatedAt());
$this->assertCount(0, $cat->getServices());
}
public function testSetName(): void
{
$cat = new ServiceCategory('Web', 'web');
$cat->setName('Email');
$this->assertSame('Email', $cat->getName());
}
public function testSetPosition(): void
{
$cat = new ServiceCategory('Web', 'web');
$cat->setPosition(3);
$this->assertSame(3, $cat->getPosition());
}
}

View File

@@ -0,0 +1,113 @@
<?php
namespace App\Tests\Entity;
use App\Entity\Service;
use App\Entity\ServiceCategory;
use App\Entity\ServiceStatusHistory;
use PHPUnit\Framework\TestCase;
class ServiceTest extends TestCase
{
private function createService(): Service
{
$category = new ServiceCategory('Web', 'web');
return new Service('Esy-Web', 'esy-web', $category);
}
public function testConstructor(): void
{
$service = $this->createService();
$this->assertNull($service->getId());
$this->assertSame('Esy-Web', $service->getName());
$this->assertSame('esy-web', $service->getSlug());
$this->assertSame('up', $service->getStatus());
$this->assertNull($service->getMessage());
$this->assertNull($service->getUrl());
$this->assertFalse($service->isExternal());
$this->assertNull($service->getExternalType());
$this->assertSame(0, $service->getPosition());
$this->assertInstanceOf(\DateTimeImmutable::class, $service->getCreatedAt());
$this->assertNull($service->getUpdatedAt());
}
public function testSetName(): void
{
$service = $this->createService();
$service->setName('Esy-Mail');
$this->assertSame('Esy-Mail', $service->getName());
}
public function testSetUrl(): void
{
$service = $this->createService();
$service->setUrl('https://example.com');
$this->assertSame('https://example.com', $service->getUrl());
}
public function testSetStatus(): void
{
$service = $this->createService();
$service->setStatus('down', 'Server error');
$this->assertSame('down', $service->getStatus());
$this->assertSame('Server error', $service->getMessage());
}
public function testExternal(): void
{
$service = $this->createService();
$service->setIsExternal(true);
$service->setExternalType('http');
$this->assertTrue($service->isExternal());
$this->assertSame('http', $service->getExternalType());
}
public function testPosition(): void
{
$service = $this->createService();
$service->setPosition(5);
$this->assertSame(5, $service->getPosition());
}
public function testStatusHistory(): void
{
$service = $this->createService();
$this->assertCount(0, $service->getStatusHistory());
}
public function testCategory(): void
{
$service = $this->createService();
$this->assertSame('Web', $service->getCategory()->getName());
}
public function testComputeUptimeRatioAllUp(): void
{
$service = $this->createService();
$history = [
new ServiceStatusHistory($service, 'up'),
new ServiceStatusHistory($service, 'up'),
];
$this->assertSame(100.0, $service->computeUptimeRatio($history));
}
public function testComputeUptimeRatioMixed(): void
{
$service = $this->createService();
$history = [
new ServiceStatusHistory($service, 'up'),
new ServiceStatusHistory($service, 'down'),
];
$ratio = $service->computeUptimeRatio($history);
// Both entries created at same instant, so uptime is based on current status
$this->assertGreaterThanOrEqual(0.0, $ratio);
$this->assertLessThanOrEqual(100.0, $ratio);
}
public function testComputeUptimeRatioEmpty(): void
{
$service = $this->createService();
$this->assertSame(100.0, $service->computeUptimeRatio([]));
}
}

View File

@@ -113,4 +113,69 @@ class UserExtendedTest extends TestCase
$user = $this->createUser();
$this->assertSame('test@test.com', $user->getUserIdentifier());
}
public function testSetIsEmailAuthEnabled(): void
{
$user = $this->createUser();
$user->setIsEmailAuthEnabled(true);
$this->assertTrue($user->isEmailAuthEnabled());
$user->setKeycloakId('kc-123');
$this->assertFalse($user->isEmailAuthEnabled());
}
public function testSetIsGoogleAuthEnabled(): void
{
$user = $this->createUser();
$user->setIsGoogleAuthEnabled(true);
$this->assertFalse($user->isGoogleAuthenticatorEnabled());
$user->setGoogleAuthenticatorSecret('SECRET');
$this->assertTrue($user->isGoogleAuthenticatorEnabled());
}
public function testClearTempPassword(): void
{
$user = $this->createUser();
$user->setTempPassword('temp');
$user->clearTempPassword();
$this->assertFalse($user->hasTempPassword());
}
public function testGenerateBackupCodes(): void
{
$user = $this->createUser();
$user->generateBackupCodes(5);
$this->assertCount(5, $user->getBackupCodes());
}
public function testSerializeUnserialize(): void
{
$user = $this->createUser();
$serialized = $user->__serialize();
$this->assertArrayHasKey('id', $serialized);
$this->assertArrayHasKey('email', $serialized);
$newUser = new User();
$newUser->__unserialize($serialized);
$this->assertSame('test@test.com', $newUser->getEmail());
}
public function testCreatedAt(): void
{
$user = $this->createUser();
$this->assertInstanceOf(\DateTimeImmutable::class, $user->getCreatedAt());
}
public function testUpdatedAt(): void
{
$user = $this->createUser();
$this->assertNull($user->getUpdatedAt());
}
public function testEraseCredentials(): void
{
$user = $this->createUser();
$user->eraseCredentials();
$this->addToAssertionCount(1);
}
}