feat: entité Domain liée à Customer avec migration

Entity Domain :
- customer (ManyToOne, CASCADE) : client propriétaire du domaine
- fqdn (unique) : nom de domaine complet, lowercase auto
- registrar : bureau d'enregistrement (OVH, Gandi, etc.)
- zoneCloudflare : statut zone Cloudflare (active, pending, etc.)
- zoneIdCloudflare : identifiant zone Cloudflare
- expiredAt : date d'expiration du domaine
- isGestion : domaine géré par SITECONSEIL
- isBilling : domaine facturé par SITECONSEIL
- createdAt / updatedAt : timestamps
- isExpired() : vérifie si le domaine est expiré
- isExpiringSoon(days) : vérifie si expiration dans les N jours

DomainTest (4 tests, 25 assertions) :
- testConstructor : valeurs par défaut, fqdn lowercase/trim
- testSetters : tous les setters/getters
- testIsExpired : null/passé/futur
- testIsExpiringSoon : null/15j (true pour 30j)/60j (false pour 30j)

Migration : CREATE TABLE domain avec FK customer ON DELETE CASCADE

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Serreau Jovann
2026-04-04 00:02:30 +02:00
parent fe42f221a6
commit 817fad4150
3 changed files with 309 additions and 0 deletions

View File

@@ -0,0 +1,97 @@
<?php
namespace App\Tests\Entity;
use App\Entity\Customer;
use App\Entity\Domain;
use App\Entity\User;
use PHPUnit\Framework\TestCase;
class DomainTest extends TestCase
{
private function createCustomer(): Customer
{
$user = new User();
$user->setEmail('c@t.com');
$user->setFirstName('C');
$user->setLastName('T');
$user->setPassword('h');
return new Customer($user);
}
public function testConstructor(): void
{
$customer = $this->createCustomer();
$domain = new Domain($customer, 'Example.COM ');
$this->assertNull($domain->getId());
$this->assertSame($customer, $domain->getCustomer());
$this->assertSame('example.com', $domain->getFqdn());
$this->assertNull($domain->getRegistrar());
$this->assertNull($domain->getZoneCloudflare());
$this->assertNull($domain->getZoneIdCloudflare());
$this->assertNull($domain->getExpiredAt());
$this->assertFalse($domain->isGestion());
$this->assertFalse($domain->isBilling());
$this->assertInstanceOf(\DateTimeImmutable::class, $domain->getCreatedAt());
$this->assertNull($domain->getUpdatedAt());
}
public function testSetters(): void
{
$domain = new Domain($this->createCustomer(), 'siteconseil.fr');
$domain->setFqdn(' ESY-WEB.DEV ');
$this->assertSame('esy-web.dev', $domain->getFqdn());
$domain->setRegistrar('OVH');
$this->assertSame('OVH', $domain->getRegistrar());
$domain->setZoneCloudflare('active');
$this->assertSame('active', $domain->getZoneCloudflare());
$domain->setZoneIdCloudflare('zone_abc123');
$this->assertSame('zone_abc123', $domain->getZoneIdCloudflare());
$expiry = new \DateTimeImmutable('2027-01-01');
$domain->setExpiredAt($expiry);
$this->assertSame($expiry, $domain->getExpiredAt());
$domain->setIsGestion(true);
$this->assertTrue($domain->isGestion());
$domain->setIsBilling(true);
$this->assertTrue($domain->isBilling());
$now = new \DateTimeImmutable();
$domain->setUpdatedAt($now);
$this->assertSame($now, $domain->getUpdatedAt());
}
public function testIsExpired(): void
{
$domain = new Domain($this->createCustomer(), 'test.fr');
$this->assertFalse($domain->isExpired());
$domain->setExpiredAt(new \DateTimeImmutable('-1 day'));
$this->assertTrue($domain->isExpired());
$domain->setExpiredAt(new \DateTimeImmutable('+1 year'));
$this->assertFalse($domain->isExpired());
}
public function testIsExpiringSoon(): void
{
$domain = new Domain($this->createCustomer(), 'test.fr');
$this->assertFalse($domain->isExpiringSoon());
$domain->setExpiredAt(new \DateTimeImmutable('+15 days'));
$this->assertTrue($domain->isExpiringSoon(30));
$domain->setExpiredAt(new \DateTimeImmutable('+60 days'));
$this->assertFalse($domain->isExpiringSoon(30));
}
}