feat: entité Website liée à Customer avec UUID, type et state machine
Entity Website : - customer (ManyToOne, CASCADE) : client propriétaire - name : nom du site - uuid : UUID v4 auto-généré (unique, 36 chars) - type : vitrine | ecommerce - state : created → install_progress → open → suspended → closed - createdAt / updatedAt (auto sur setState) - isOpen() : vérifie si state === open WebsiteTest (5 tests, 20 assertions) : - testConstructor : valeurs par défaut, uuid 36 chars, type vitrine - testConstructorEcommerce : type ecommerce - testSetters : name, type, updatedAt - testState : transitions created→install_progress→open→suspended→closed - testUuidUnique : 2 sites ont des uuid différents Dépendance : symfony/uid ajouté pour Uuid::v4() Migration : CREATE TABLE website avec FK customer, uuid unique Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
87
tests/Entity/WebsiteTest.php
Normal file
87
tests/Entity/WebsiteTest.php
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace App\Tests\Entity;
|
||||
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\User;
|
||||
use App\Entity\Website;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class WebsiteTest 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();
|
||||
$site = new Website($customer, 'Mon Site');
|
||||
|
||||
$this->assertNull($site->getId());
|
||||
$this->assertSame($customer, $site->getCustomer());
|
||||
$this->assertSame('Mon Site', $site->getName());
|
||||
$this->assertSame(36, \strlen($site->getUuid()));
|
||||
$this->assertSame(Website::TYPE_VITRINE, $site->getType());
|
||||
$this->assertSame(Website::STATE_CREATED, $site->getState());
|
||||
$this->assertInstanceOf(\DateTimeImmutable::class, $site->getCreatedAt());
|
||||
$this->assertNull($site->getUpdatedAt());
|
||||
}
|
||||
|
||||
public function testConstructorEcommerce(): void
|
||||
{
|
||||
$site = new Website($this->createCustomer(), 'Boutique', Website::TYPE_ECOMMERCE);
|
||||
$this->assertSame(Website::TYPE_ECOMMERCE, $site->getType());
|
||||
}
|
||||
|
||||
public function testSetters(): void
|
||||
{
|
||||
$site = new Website($this->createCustomer(), 'Test');
|
||||
|
||||
$site->setName('Nouveau nom');
|
||||
$this->assertSame('Nouveau nom', $site->getName());
|
||||
|
||||
$site->setType(Website::TYPE_ECOMMERCE);
|
||||
$this->assertSame(Website::TYPE_ECOMMERCE, $site->getType());
|
||||
|
||||
$now = new \DateTimeImmutable();
|
||||
$site->setUpdatedAt($now);
|
||||
$this->assertSame($now, $site->getUpdatedAt());
|
||||
}
|
||||
|
||||
public function testState(): void
|
||||
{
|
||||
$site = new Website($this->createCustomer(), 'Test');
|
||||
$this->assertFalse($site->isOpen());
|
||||
|
||||
$site->setState(Website::STATE_INSTALL_PROGRESS);
|
||||
$this->assertSame(Website::STATE_INSTALL_PROGRESS, $site->getState());
|
||||
$this->assertFalse($site->isOpen());
|
||||
|
||||
$site->setState(Website::STATE_OPEN);
|
||||
$this->assertTrue($site->isOpen());
|
||||
$this->assertInstanceOf(\DateTimeImmutable::class, $site->getUpdatedAt());
|
||||
|
||||
$site->setState(Website::STATE_SUSPENDED);
|
||||
$this->assertFalse($site->isOpen());
|
||||
|
||||
$site->setState(Website::STATE_CLOSED);
|
||||
$this->assertFalse($site->isOpen());
|
||||
}
|
||||
|
||||
public function testUuidUnique(): void
|
||||
{
|
||||
$customer = $this->createCustomer();
|
||||
$site1 = new Website($customer, 'Site 1');
|
||||
$site2 = new Website($customer, 'Site 2');
|
||||
|
||||
$this->assertNotSame($site1->getUuid(), $site2->getUuid());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user