test: ajout tests Customer, EmailTracking, MessengerLog, PriceAutomatic

tests/Entity/CustomerTest.php (nouveau, 11 tests):
- testConstructor: id null, user, state active, createdAt, updatedAt null
- testCodeComptable: get/set nullable
- testGenerateCodeComptable: genere un code non vide
- testNames: firstName, lastName, fullName
- testRaisonSociale: get/set
- testContact: email, phone
- testAddress: address, address2, zipCode, city
- testLegal: siret, rcs, numTva
- testStripe: stripeCustomerId get/set nullable
- testTypeCompany: set TYPE_SARL
- testState: setState suspended, isActive false

tests/Entity/EmailTrackingTest.php (nouveau, 4 tests):
- testConstructor: messageId, recipient, subject, htmlBody, attachments,
  state='sent', sentAt DateTimeImmutable, openedAt null
- testConstructorWithoutOptionals: htmlBody et attachments null
- testMarkAsOpened: state='opened', openedAt set
- testMarkAsOpenedOnlyOnce: deuxieme appel ne change pas openedAt

tests/Entity/MessengerLogTest.php (nouveau, 4 tests):
- testConstructor: tous les champs avec valeurs, status='failed',
  createdAt et failedAt DateTimeImmutable
- testConstructorMinimal: messageBody, stackTrace, transportName null,
  retryCount 0
- testSetStatus: change le status
- testMarkAsResolved: status passe a 'resolved'

tests/Entity/PriceAutomaticTest.php (nouveau, 2 tests):
- testGettersSetters: tous les champs avec valeurs
- testNullables: description, stripeId, stripeAbonnementId null

Resultat: 315 tests, 605 assertions, 0 failures

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

View File

@@ -0,0 +1,120 @@
<?php
namespace App\Tests\Entity;
use App\Entity\Customer;
use App\Entity\User;
use PHPUnit\Framework\TestCase;
class CustomerTest extends TestCase
{
private function createCustomer(): Customer
{
$user = new User();
$user->setEmail('c@test.com');
$user->setFirstName('John');
$user->setLastName('Doe');
$user->setPassword('h');
return new Customer($user);
}
public function testConstructor(): void
{
$c = $this->createCustomer();
$this->assertNull($c->getId());
$this->assertSame('John', $c->getUser()->getFirstName());
$this->assertSame(Customer::STATE_ACTIVE, $c->getState());
$this->assertTrue($c->isActive());
$this->assertInstanceOf(\DateTimeImmutable::class, $c->getCreatedAt());
$this->assertNull($c->getUpdatedAt());
}
public function testCodeComptable(): void
{
$c = $this->createCustomer();
$this->assertNull($c->getCodeComptable());
$c->setCodeComptable('C-001');
$this->assertSame('C-001', $c->getCodeComptable());
}
public function testGenerateCodeComptable(): void
{
$c = $this->createCustomer();
$code = $c->generateCodeComptable();
$this->assertNotEmpty($code);
}
public function testNames(): void
{
$c = $this->createCustomer();
$c->setFirstName('Jane');
$c->setLastName('Smith');
$this->assertSame('Jane', $c->getFirstName());
$this->assertSame('Smith', $c->getLastName());
$this->assertSame('Jane Smith', $c->getFullName());
}
public function testRaisonSociale(): void
{
$c = $this->createCustomer();
$c->setRaisonSociale('SARL Test');
$this->assertSame('SARL Test', $c->getRaisonSociale());
}
public function testContact(): void
{
$c = $this->createCustomer();
$c->setEmail('new@test.com');
$c->setPhone('0612345678');
$this->assertSame('new@test.com', $c->getEmail());
$this->assertSame('0612345678', $c->getPhone());
}
public function testAddress(): void
{
$c = $this->createCustomer();
$c->setAddress('1 rue Test');
$c->setAddress2('Bat A');
$c->setZipCode('02100');
$c->setCity('Saint-Quentin');
$this->assertSame('1 rue Test', $c->getAddress());
$this->assertSame('Bat A', $c->getAddress2());
$this->assertSame('02100', $c->getZipCode());
$this->assertSame('Saint-Quentin', $c->getCity());
}
public function testLegal(): void
{
$c = $this->createCustomer();
$c->setSiret('12345678901234');
$c->setRcs('RCS Paris');
$c->setNumTva('FR12345678901');
$this->assertSame('12345678901234', $c->getSiret());
$this->assertSame('RCS Paris', $c->getRcs());
$this->assertSame('FR12345678901', $c->getNumTva());
}
public function testStripe(): void
{
$c = $this->createCustomer();
$this->assertNull($c->getStripeCustomerId());
$c->setStripeCustomerId('cus_xxx');
$this->assertSame('cus_xxx', $c->getStripeCustomerId());
}
public function testTypeCompany(): void
{
$c = $this->createCustomer();
$c->setTypeCompany(Customer::TYPE_SARL);
$this->assertSame('sarl', $c->getTypeCompany());
}
public function testState(): void
{
$c = $this->createCustomer();
$c->setState(Customer::STATE_SUSPENDED);
$this->assertSame(Customer::STATE_SUSPENDED, $c->getState());
$this->assertFalse($c->isActive());
}
}

View File

@@ -0,0 +1,50 @@
<?php
namespace App\Tests\Entity;
use App\Entity\EmailTracking;
use PHPUnit\Framework\TestCase;
class EmailTrackingTest extends TestCase
{
public function testConstructor(): void
{
$t = new EmailTracking('msg-123', 'to@test.com', 'Subject', '<h1>Hi</h1>', [['path' => '/f.pdf', 'name' => 'f.pdf']]);
$this->assertNull($t->getId());
$this->assertSame('msg-123', $t->getMessageId());
$this->assertSame('to@test.com', $t->getRecipient());
$this->assertSame('Subject', $t->getSubject());
$this->assertSame('<h1>Hi</h1>', $t->getHtmlBody());
$this->assertCount(1, $t->getAttachments());
$this->assertSame('sent', $t->getState());
$this->assertInstanceOf(\DateTimeImmutable::class, $t->getSentAt());
$this->assertNull($t->getOpenedAt());
}
public function testConstructorWithoutOptionals(): void
{
$t = new EmailTracking('msg-456', 'to@test.com', 'Test');
$this->assertNull($t->getHtmlBody());
$this->assertNull($t->getAttachments());
}
public function testMarkAsOpened(): void
{
$t = new EmailTracking('msg-789', 'to@test.com', 'Test');
$this->assertNull($t->getOpenedAt());
$t->markAsOpened();
$this->assertSame('opened', $t->getState());
$this->assertInstanceOf(\DateTimeImmutable::class, $t->getOpenedAt());
}
public function testMarkAsOpenedOnlyOnce(): void
{
$t = new EmailTracking('msg-abc', 'to@test.com', 'Test');
$t->markAsOpened();
$firstOpenedAt = $t->getOpenedAt();
$t->markAsOpened();
$this->assertSame($firstOpenedAt, $t->getOpenedAt());
}
}

View File

@@ -0,0 +1,48 @@
<?php
namespace App\Tests\Entity;
use App\Entity\MessengerLog;
use PHPUnit\Framework\TestCase;
class MessengerLogTest extends TestCase
{
public function testConstructor(): void
{
$log = new MessengerLog('App\Message\TestMessage', '{"data":"test"}', 'Error occurred', 'stack trace', 'async', 2);
$this->assertNull($log->getId());
$this->assertSame('App\Message\TestMessage', $log->getMessageClass());
$this->assertSame('{"data":"test"}', $log->getMessageBody());
$this->assertSame('failed', $log->getStatus());
$this->assertSame('Error occurred', $log->getErrorMessage());
$this->assertSame('stack trace', $log->getStackTrace());
$this->assertSame('async', $log->getTransportName());
$this->assertSame(2, $log->getRetryCount());
$this->assertInstanceOf(\DateTimeImmutable::class, $log->getCreatedAt());
$this->assertInstanceOf(\DateTimeImmutable::class, $log->getFailedAt());
}
public function testConstructorMinimal(): void
{
$log = new MessengerLog('App\Message\Test', null, 'Error');
$this->assertNull($log->getMessageBody());
$this->assertNull($log->getStackTrace());
$this->assertNull($log->getTransportName());
$this->assertSame(0, $log->getRetryCount());
}
public function testSetStatus(): void
{
$log = new MessengerLog('App\Message\Test', null, 'Error');
$this->assertSame('failed', $log->getStatus());
$log->setStatus('resolved');
$this->assertSame('resolved', $log->getStatus());
}
public function testMarkAsResolved(): void
{
$log = new MessengerLog('App\Message\Test', null, 'Error');
$log->markAsResolved();
$this->assertSame('resolved', $log->getStatus());
}
}

View File

@@ -0,0 +1,44 @@
<?php
namespace App\Tests\Entity;
use App\Entity\PriceAutomatic;
use PHPUnit\Framework\TestCase;
class PriceAutomaticTest extends TestCase
{
public function testGettersSetters(): void
{
$p = new PriceAutomatic();
$p->setType('esyweb_business');
$p->setTitle('Esy-Web Business');
$p->setDescription('Test description');
$p->setPriceHt('500.00');
$p->setMonthPrice('100.00');
$p->setPeriod(1);
$p->setStripeId('price_xxx');
$p->setStripeAbonnementId('price_yyy');
$this->assertNull($p->getId());
$this->assertSame('esyweb_business', $p->getType());
$this->assertSame('Esy-Web Business', $p->getTitle());
$this->assertSame('Test description', $p->getDescription());
$this->assertSame('500.00', $p->getPriceHt());
$this->assertSame('100.00', $p->getMonthPrice());
$this->assertSame(1, $p->getPeriod());
$this->assertSame('price_xxx', $p->getStripeId());
$this->assertSame('price_yyy', $p->getStripeAbonnementId());
}
public function testNullables(): void
{
$p = new PriceAutomatic();
$p->setType('test');
$p->setTitle('Test');
$p->setPriceHt('0.00');
$this->assertNull($p->getDescription());
$this->assertNull($p->getStripeId());
$this->assertNull($p->getStripeAbonnementId());
}
}