Files
crm_ecosplay/tests/Entity/AdvertEventTest.php
Serreau Jovann 79c55ba0f9 test: ajout 163 tests unitaires (668->831) avec couverture 73%
Entites (76 tests) :
- PrestataireTest : constructeur, setters, getFullAddress, getTotalPaidHt
- FacturePrestataireTest : constructeur, getPeriodLabel 12 mois, Vich upload
- AdvertPaymentTest : constructeur, types constants, method
- AdvertEventTest : constructeur, getTypeLabel, 5 types + fallback
- FactureLineTest : constructeur, setters, optionnels nullable
- ActionLogTest : constructeur, 10 action constants, severity
- PaymentReminderTest : 8 steps, getStepLabel, getSeverity
- DocusealEventTest : constructeur, nullable fields

Commands (16 tests) :
- ReminderFacturesPrestataireCommandTest : 6 scenarios (aucun presta,
  tous OK, factures manquantes, SIRET vide, mois different)
- PaymentReminderCommandTest : 10 scenarios (skip recent, J+15 emails,
  suspension, termination, exception handling)

Services PDF (24 tests) :
- ComptaPdfTest : empty/FEC/multi-page, totaux Debit/Credit
- RapportFinancierPdfTest : recettes/depenses, bilan equilibre/deficit/excedent
- FacturePdfTest : lignes, TVA, customer address, paid badge, multi-page

Controllers (47 tests) :
- ComptabiliteControllerTest : 18 tests (index, 7 exports CSV, 2 JSON,
  4 PDF, 2 rapport financier)
- PrestatairesControllerTest : 19 tests (CRUD, factures, SIRET proxy)
- FactureControllerTest : 6 tests (search, send)
- FactureVerifyControllerTest : 4 tests (HMAC valid/invalid/not found)

Couverture : 51%->60% classes, 58%->73% methodes

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 23:57:42 +02:00

98 lines
3.3 KiB
PHP

<?php
namespace App\Tests\Entity;
use App\Entity\Advert;
use App\Entity\AdvertEvent;
use App\Entity\OrderNumber;
use PHPUnit\Framework\TestCase;
class AdvertEventTest extends TestCase
{
private function createAdvert(): Advert
{
$order = new OrderNumber('04/2026-99002');
return new Advert($order, 'test-secret');
}
public function testConstructorMinimalArgs(): void
{
$advert = $this->createAdvert();
$event = new AdvertEvent($advert, AdvertEvent::TYPE_VIEW);
$this->assertNull($event->getId());
$this->assertSame($advert, $event->getAdvert());
$this->assertSame(AdvertEvent::TYPE_VIEW, $event->getType());
$this->assertNull($event->getDetails());
$this->assertNull($event->getIp());
$this->assertInstanceOf(\DateTimeImmutable::class, $event->getCreatedAt());
}
public function testConstructorWithAllArgs(): void
{
$advert = $this->createAdvert();
$event = new AdvertEvent($advert, AdvertEvent::TYPE_PAY, 'Paiement CB', '192.168.1.1');
$this->assertSame(AdvertEvent::TYPE_PAY, $event->getType());
$this->assertSame('Paiement CB', $event->getDetails());
$this->assertSame('192.168.1.1', $event->getIp());
}
public function testTypeConstants(): void
{
$this->assertSame('view', AdvertEvent::TYPE_VIEW);
$this->assertSame('pay', AdvertEvent::TYPE_PAY);
$this->assertSame('mail_open', AdvertEvent::TYPE_MAIL_OPEN);
$this->assertSame('mail_send', AdvertEvent::TYPE_MAIL_SEND);
$this->assertSame('reminder', AdvertEvent::TYPE_REMINDER);
}
public function testGetTypeLabelView(): void
{
$event = new AdvertEvent($this->createAdvert(), AdvertEvent::TYPE_VIEW);
$this->assertSame('Page consultee', $event->getTypeLabel());
}
public function testGetTypeLabelPay(): void
{
$event = new AdvertEvent($this->createAdvert(), AdvertEvent::TYPE_PAY);
$this->assertSame('Paiement effectue', $event->getTypeLabel());
}
public function testGetTypeLabelMailOpen(): void
{
$event = new AdvertEvent($this->createAdvert(), AdvertEvent::TYPE_MAIL_OPEN);
$this->assertSame('Email ouvert', $event->getTypeLabel());
}
public function testGetTypeLabelMailSend(): void
{
$event = new AdvertEvent($this->createAdvert(), AdvertEvent::TYPE_MAIL_SEND);
$this->assertSame('Email envoye', $event->getTypeLabel());
}
public function testGetTypeLabelReminder(): void
{
$event = new AdvertEvent($this->createAdvert(), AdvertEvent::TYPE_REMINDER);
$this->assertSame('Relance envoyee', $event->getTypeLabel());
}
public function testGetTypeLabelUnknown(): void
{
$event = new AdvertEvent($this->createAdvert(), 'custom_type');
$this->assertSame('custom_type', $event->getTypeLabel());
}
public function testCreatedAtTimestamp(): void
{
$advert = $this->createAdvert();
$before = new \DateTimeImmutable();
$event = new AdvertEvent($advert, AdvertEvent::TYPE_VIEW);
$after = new \DateTimeImmutable();
$this->assertGreaterThanOrEqual($before, $event->getCreatedAt());
$this->assertLessThanOrEqual($after, $event->getCreatedAt());
}
}