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>
141 lines
4.5 KiB
PHP
141 lines
4.5 KiB
PHP
<?php
|
|
|
|
namespace App\Tests\Entity;
|
|
|
|
use App\Entity\FacturePrestataire;
|
|
use App\Entity\Prestataire;
|
|
use PHPUnit\Framework\TestCase;
|
|
use Symfony\Component\HttpFoundation\File\File;
|
|
|
|
class FacturePrestataireTest extends TestCase
|
|
{
|
|
private function createPrestataire(): Prestataire
|
|
{
|
|
return new Prestataire('Test Prestataire SARL');
|
|
}
|
|
|
|
public function testConstructor(): void
|
|
{
|
|
$p = $this->createPrestataire();
|
|
$f = new FacturePrestataire($p, 'FACT-2026-001', 2026, 4);
|
|
|
|
$this->assertNull($f->getId());
|
|
$this->assertSame($p, $f->getPrestataire());
|
|
$this->assertSame('FACT-2026-001', $f->getNumFacture());
|
|
$this->assertSame(2026, $f->getYear());
|
|
$this->assertSame(4, $f->getMonth());
|
|
$this->assertSame('0.00', $f->getMontantHt());
|
|
$this->assertSame('0.00', $f->getMontantTtc());
|
|
$this->assertFalse($f->isPaid());
|
|
$this->assertNull($f->getPaidAt());
|
|
$this->assertNull($f->getFacturePdf());
|
|
$this->assertNull($f->getFacturePdfFile());
|
|
$this->assertNull($f->getUpdatedAt());
|
|
$this->assertInstanceOf(\DateTimeImmutable::class, $f->getCreatedAt());
|
|
}
|
|
|
|
public function testNumFacture(): void
|
|
{
|
|
$f = new FacturePrestataire($this->createPrestataire(), 'OLD-001', 2026, 1);
|
|
$f->setNumFacture('NEW-002');
|
|
$this->assertSame('NEW-002', $f->getNumFacture());
|
|
}
|
|
|
|
public function testMontants(): void
|
|
{
|
|
$f = new FacturePrestataire($this->createPrestataire(), 'FACT-001', 2026, 3);
|
|
|
|
$f->setMontantHt('1500.00');
|
|
$this->assertSame('1500.00', $f->getMontantHt());
|
|
|
|
$f->setMontantTtc('1800.00');
|
|
$this->assertSame('1800.00', $f->getMontantTtc());
|
|
}
|
|
|
|
public function testYearAndMonth(): void
|
|
{
|
|
$f = new FacturePrestataire($this->createPrestataire(), 'FACT-001', 2025, 12);
|
|
$f->setYear(2026);
|
|
$this->assertSame(2026, $f->getYear());
|
|
$f->setMonth(1);
|
|
$this->assertSame(1, $f->getMonth());
|
|
}
|
|
|
|
public function testIsPaid(): void
|
|
{
|
|
$f = new FacturePrestataire($this->createPrestataire(), 'FACT-001', 2026, 4);
|
|
$this->assertFalse($f->isPaid());
|
|
|
|
$f->setIsPaid(true);
|
|
$this->assertTrue($f->isPaid());
|
|
|
|
$f->setIsPaid(false);
|
|
$this->assertFalse($f->isPaid());
|
|
}
|
|
|
|
public function testPaidAt(): void
|
|
{
|
|
$f = new FacturePrestataire($this->createPrestataire(), 'FACT-001', 2026, 4);
|
|
$this->assertNull($f->getPaidAt());
|
|
|
|
$now = new \DateTimeImmutable();
|
|
$f->setPaidAt($now);
|
|
$this->assertSame($now, $f->getPaidAt());
|
|
|
|
$f->setPaidAt(null);
|
|
$this->assertNull($f->getPaidAt());
|
|
}
|
|
|
|
public function testFacturePdf(): void
|
|
{
|
|
$f = new FacturePrestataire($this->createPrestataire(), 'FACT-001', 2026, 4);
|
|
$this->assertNull($f->getFacturePdf());
|
|
|
|
$f->setFacturePdf('facture-2026-001.pdf');
|
|
$this->assertSame('facture-2026-001.pdf', $f->getFacturePdf());
|
|
|
|
$f->setFacturePdf(null);
|
|
$this->assertNull($f->getFacturePdf());
|
|
}
|
|
|
|
public function testSetFacturePdfFileTriggersUpdatedAt(): void
|
|
{
|
|
$f = new FacturePrestataire($this->createPrestataire(), 'FACT-001', 2026, 4);
|
|
$this->assertNull($f->getUpdatedAt());
|
|
|
|
$file = $this->createStub(File::class);
|
|
$f->setFacturePdfFile($file);
|
|
|
|
$this->assertSame($file, $f->getFacturePdfFile());
|
|
$this->assertInstanceOf(\DateTimeImmutable::class, $f->getUpdatedAt());
|
|
}
|
|
|
|
public function testSetFacturePdfFileNullDoesNotSetUpdatedAt(): void
|
|
{
|
|
$f = new FacturePrestataire($this->createPrestataire(), 'FACT-001', 2026, 4);
|
|
$f->setFacturePdfFile(null);
|
|
$this->assertNull($f->getUpdatedAt());
|
|
$this->assertNull($f->getFacturePdfFile());
|
|
}
|
|
|
|
public function testGetPeriodLabelKnownMonths(): void
|
|
{
|
|
$months = [
|
|
1 => 'Janvier', 2 => 'Fevrier', 3 => 'Mars', 4 => 'Avril',
|
|
5 => 'Mai', 6 => 'Juin', 7 => 'Juillet', 8 => 'Aout',
|
|
9 => 'Septembre', 10 => 'Octobre', 11 => 'Novembre', 12 => 'Decembre',
|
|
];
|
|
|
|
foreach ($months as $num => $name) {
|
|
$f = new FacturePrestataire($this->createPrestataire(), 'F', 2026, $num);
|
|
$this->assertSame($name.' 2026', $f->getPeriodLabel());
|
|
}
|
|
}
|
|
|
|
public function testGetPeriodLabelUnknownMonth(): void
|
|
{
|
|
$f = new FacturePrestataire($this->createPrestataire(), 'F', 2026, 13);
|
|
$this->assertSame('13 2026', $f->getPeriodLabel());
|
|
}
|
|
}
|