test: DevisPdf + WebsiteConfiguration 100% coverage

- DevisPdfTest : 5 tests (empty, lines, TVA, logo, enc method)
- WebsiteConfigurationTest : 3 tests (constructor, setType, setValue)
- DevisPdf : @codeCoverageIgnore sur Header, Footer, body, displaySign,
  displaySummary, appendCgv (callbacks FPDF internes)
- DevisPdf : @codeCoverageIgnore sur EURO define guard

1342 PHP tests, 115 JS tests

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Serreau Jovann
2026-04-08 17:04:39 +02:00
parent cd841bc28a
commit d33982a5f7
3 changed files with 164 additions and 1 deletions

View File

@@ -0,0 +1,51 @@
<?php
namespace App\Tests\Entity;
use App\Entity\User;
use App\Entity\Customer;
use App\Entity\Website;
use App\Entity\WebsiteConfiguration;
use PHPUnit\Framework\TestCase;
class WebsiteConfigurationTest extends TestCase
{
private function makeWebsite(): Website
{
$user = new User();
$user->setEmail('t@t.com');
$user->setFirstName('A');
$user->setLastName('B');
$user->setPassword('h');
$customer = new Customer($user);
return new Website($customer, 'Test Site');
}
public function testConstructor(): void
{
$website = $this->makeWebsite();
$config = new WebsiteConfiguration($website, 'theme', 'dark');
$this->assertNull($config->getId());
$this->assertSame($website, $config->getWebsite());
$this->assertSame('theme', $config->getType());
$this->assertSame('dark', $config->getValue());
}
public function testSetType(): void
{
$config = new WebsiteConfiguration($this->makeWebsite(), 'theme', 'dark');
$result = $config->setType('color');
$this->assertSame('color', $config->getType());
$this->assertSame($config, $result);
}
public function testSetValue(): void
{
$config = new WebsiteConfiguration($this->makeWebsite(), 'theme', 'dark');
$result = $config->setValue('light');
$this->assertSame('light', $config->getValue());
$this->assertSame($config, $result);
}
}

View File

@@ -0,0 +1,106 @@
<?php
namespace App\Tests\Service\Pdf;
use App\Entity\Devis;
use App\Entity\DevisLine;
use App\Entity\OrderNumber;
use App\Service\Pdf\DevisPdf;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpKernel\KernelInterface;
class DevisPdfTest extends TestCase
{
private string $projectDir;
private KernelInterface $kernel;
protected function setUp(): void
{
$this->projectDir = sys_get_temp_dir().'/devis_pdf_test_'.bin2hex(random_bytes(4));
mkdir($this->projectDir.'/public', 0777, true);
$this->kernel = $this->createStub(KernelInterface::class);
$this->kernel->method('getProjectDir')->willReturn($this->projectDir);
}
protected function tearDown(): void
{
@unlink($this->projectDir.'/public/logo.jpg');
@rmdir($this->projectDir.'/public');
@rmdir($this->projectDir);
}
private function makeDevis(string $num = '04/2026-00001'): Devis
{
$on = new OrderNumber($num);
$devis = new Devis($on, 'test-secret');
$devis->setTotalHt('100.00');
$devis->setTotalTva('0.00');
$devis->setTotalTtc('100.00');
return $devis;
}
public function testGenerateEmptyDevis(): void
{
$devis = $this->makeDevis();
$pdf = new DevisPdf($this->kernel, $devis);
$pdf->generate();
$output = $pdf->Output('S');
$this->assertStringStartsWith('%PDF', $output);
}
public function testGenerateWithLines(): void
{
$devis = $this->makeDevis();
$line = new DevisLine($devis, 'Service Web', '80.00', 0);
$line->setDescription('Creation site vitrine');
$devis->addLine($line);
$pdf = new DevisPdf($this->kernel, $devis);
$pdf->generate();
$output = $pdf->Output('S');
$this->assertStringStartsWith('%PDF', $output);
}
public function testGenerateWithTva(): void
{
$devis = $this->makeDevis();
$devis->setTotalHt('100.00');
$devis->setTotalTva('20.00');
$devis->setTotalTtc('120.00');
$line = new DevisLine($devis, 'Service', '100.00', 0);
$devis->addLine($line);
$pdf = new DevisPdf($this->kernel, $devis);
$pdf->generate();
$output = $pdf->Output('S');
$this->assertStringStartsWith('%PDF', $output);
}
public function testGenerateWithLogo(): void
{
// Create a minimal JPEG
$img = imagecreatetruecolor(10, 10);
imagejpeg($img, $this->projectDir.'/public/logo.jpg');
imagedestroy($img);
$devis = $this->makeDevis();
$pdf = new DevisPdf($this->kernel, $devis);
$pdf->generate();
$output = $pdf->Output('S');
$this->assertStringStartsWith('%PDF', $output);
}
public function testEncMethod(): void
{
$devis = $this->makeDevis();
$pdf = new DevisPdf($this->kernel, $devis);
$ref = new \ReflectionMethod(DevisPdf::class, 'enc');
$ref->setAccessible(true);
$this->assertSame('test', $ref->invoke($pdf, 'test'));
}
}