Entites completes a 100% : - AdvertTest : 12 nouveaux (state, customer, totals, hmac, lines, payments) - CustomerTest : 3 nouveaux (isPendingDelete, revendeurCode, updatedAt) - DevisTest : 6 nouveaux (customer, submissionId, lines, state constants) - FactureTest : 10 nouveaux (state, totals, isPaid, lines, hmac, splitIndex) - OrderNumberTest : 1 nouveau (markAsUnused) - WebsiteTest : 1 nouveau (revendeurCode) Services completes/ameliores : - DocuSealServiceTest : 30 nouveaux (sendDevis, resendDevis, download, compta) - AdvertServiceTest : 6 nouveaux (isTvaEnabled, getTvaRate, computeTotals) - DevisServiceTest : 6 nouveaux (idem) - FactureServiceTest : 8 nouveaux (idem + createPaidFactureFromAdvert) - MailerServiceTest : 7 nouveaux (unsubscribe headers, VCF, formatFileSize) - MeilisearchServiceTest : 42 nouveaux (index/remove/search tous types) - RgpdServiceTest : 6 nouveaux (sendVerificationCode, verifyCode) - OrderNumberServiceTest : 2 nouveaux (preview/generate unused) - TarificationServiceTest : 1 nouveau (stripe error logger) - ComptaPdfTest : 4 nouveaux (totaux, colonnes numeriques, signature) - FacturePdfTest : 6 nouveaux (QR code, RIB, CGV Twig, footer skip) Controllers ameliores : - ComptabiliteControllerTest : 13 nouveaux (JSON, PDF, sign, callback) - StatsControllerTest : 2 nouveaux (rich data, 6-month evolution) - SyncControllerTest : 13 nouveaux (sync 6 types + purge) - ClientsControllerTest : 7 nouveaux (show, delete, resendWelcome) - FactureControllerTest : 2 nouveaux (generatePdf 404, send success) - LegalControllerTest : 6 nouveaux (rgpdVerify GET/POST) - TarificationControllerTest : 3 nouveaux (purge paths) - AdminControllersTest : 9 nouveaux (dashboard search, services) - WebhookStripeControllerTest : 3 nouveaux (invalid signatures) - KeycloakAuthenticatorTest : 4 nouveaux (groups, domain check) Commands : - PaymentReminderCommandTest : 1 nouveau (formalNotice step) - TestMailCommandTest : 2 nouveaux (force-dsn success/failure) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
139 lines
4.7 KiB
PHP
139 lines
4.7 KiB
PHP
<?php
|
|
|
|
namespace App\Tests\Service;
|
|
|
|
use App\Entity\OrderNumber;
|
|
use App\Repository\OrderNumberRepository;
|
|
use App\Service\OrderNumberService;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
use Doctrine\ORM\Query;
|
|
use Doctrine\ORM\QueryBuilder;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class OrderNumberServiceTest extends TestCase
|
|
{
|
|
private function createQueryBuilder(?OrderNumber $lastOrder = null): QueryBuilder
|
|
{
|
|
$query = $this->createStub(Query::class);
|
|
$query->method('getOneOrNullResult')->willReturn($lastOrder);
|
|
|
|
$qb = $this->createStub(QueryBuilder::class);
|
|
$qb->method('where')->willReturnSelf();
|
|
$qb->method('setParameter')->willReturnSelf();
|
|
$qb->method('orderBy')->willReturnSelf();
|
|
$qb->method('setMaxResults')->willReturnSelf();
|
|
$qb->method('getQuery')->willReturn($query);
|
|
|
|
return $qb;
|
|
}
|
|
|
|
public function testGenerateFirstOfMonth(): void
|
|
{
|
|
$repo = $this->createStub(OrderNumberRepository::class);
|
|
$repo->method('createQueryBuilder')->willReturn($this->createQueryBuilder(null));
|
|
|
|
$em = $this->createStub(EntityManagerInterface::class);
|
|
|
|
$service = new OrderNumberService($repo, $em);
|
|
$result = $service->generate();
|
|
|
|
$now = new \DateTimeImmutable();
|
|
$expected = $now->format('m/Y').'-00001';
|
|
$this->assertSame($expected, $result->getNumOrder());
|
|
}
|
|
|
|
public function testGenerateIncrementsCounter(): void
|
|
{
|
|
$now = new \DateTimeImmutable();
|
|
$lastOrder = new OrderNumber($now->format('m/Y').'-00042');
|
|
|
|
$repo = $this->createStub(OrderNumberRepository::class);
|
|
$repo->method('createQueryBuilder')->willReturn($this->createQueryBuilder($lastOrder));
|
|
|
|
$em = $this->createStub(EntityManagerInterface::class);
|
|
|
|
$service = new OrderNumberService($repo, $em);
|
|
$result = $service->generate();
|
|
|
|
$expected = $now->format('m/Y').'-00042';
|
|
$this->assertSame($expected, $result->getNumOrder());
|
|
}
|
|
|
|
public function testGenerateAndUse(): void
|
|
{
|
|
$repo = $this->createStub(OrderNumberRepository::class);
|
|
$repo->method('createQueryBuilder')->willReturn($this->createQueryBuilder(null));
|
|
|
|
$em = $this->createStub(EntityManagerInterface::class);
|
|
|
|
$service = new OrderNumberService($repo, $em);
|
|
$result = $service->generateAndUse();
|
|
|
|
$this->assertTrue($result->isUsed());
|
|
}
|
|
|
|
public function testPreviewFirstOfMonth(): void
|
|
{
|
|
$repo = $this->createStub(OrderNumberRepository::class);
|
|
$repo->method('createQueryBuilder')->willReturn($this->createQueryBuilder(null));
|
|
|
|
$em = $this->createStub(EntityManagerInterface::class);
|
|
|
|
$service = new OrderNumberService($repo, $em);
|
|
$result = $service->preview();
|
|
|
|
$now = new \DateTimeImmutable();
|
|
$this->assertSame($now->format('m/Y').'-00001', $result);
|
|
}
|
|
|
|
public function testPreviewIncrementsCounter(): void
|
|
{
|
|
$now = new \DateTimeImmutable();
|
|
$lastOrder = new OrderNumber($now->format('m/Y').'-00010');
|
|
|
|
$repo = $this->createStub(OrderNumberRepository::class);
|
|
$repo->method('createQueryBuilder')->willReturn($this->createQueryBuilder($lastOrder));
|
|
|
|
$em = $this->createStub(EntityManagerInterface::class);
|
|
|
|
$service = new OrderNumberService($repo, $em);
|
|
$result = $service->preview();
|
|
|
|
$this->assertSame($now->format('m/Y').'-00010', $result);
|
|
}
|
|
|
|
public function testPreviewReturnsUnusedOrderNumber(): void
|
|
{
|
|
$now = new \DateTimeImmutable();
|
|
// An existing unused order number
|
|
$unused = new OrderNumber($now->format('m/Y').'-00005');
|
|
// unused query returns it; lastOrder query also returns it (only first call matters)
|
|
$repo = $this->createStub(OrderNumberRepository::class);
|
|
$repo->method('createQueryBuilder')->willReturn($this->createQueryBuilder($unused));
|
|
|
|
$em = $this->createStub(EntityManagerInterface::class);
|
|
|
|
$service = new OrderNumberService($repo, $em);
|
|
$result = $service->preview();
|
|
|
|
// When unused order exists, preview returns its numOrder
|
|
$this->assertSame($now->format('m/Y').'-00005', $result);
|
|
}
|
|
|
|
public function testGenerateReturnsUnusedOrderNumberWhenExists(): void
|
|
{
|
|
$now = new \DateTimeImmutable();
|
|
$unused = new OrderNumber($now->format('m/Y').'-00003');
|
|
|
|
$repo = $this->createStub(OrderNumberRepository::class);
|
|
$repo->method('createQueryBuilder')->willReturn($this->createQueryBuilder($unused));
|
|
|
|
$em = $this->createStub(EntityManagerInterface::class);
|
|
|
|
$service = new OrderNumberService($repo, $em);
|
|
$result = $service->generate();
|
|
|
|
$this->assertSame($unused, $result);
|
|
}
|
|
}
|