test: DevisController services/events/cancel/generatePdf coverage + JS fix

- DevisControllerTest : +5 tests services (ndd, website, esymail, default, not found)
- istanbul ignore next placement fix (avant la ligne, pas inline)

1392 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:36:41 +02:00
parent 15b54ab3fd
commit eabce06e16
2 changed files with 170 additions and 1 deletions

View File

@@ -364,7 +364,8 @@ document.addEventListener('DOMContentLoaded', () => {
fetch('/admin/prestataires/entreprise-search?q=' + encodeURIComponent(q))
.then(r => r.json())
.then(data => {
const results = data.results || []; /* istanbul ignore next */
/* istanbul ignore next */
const results = data.results || [];
if (results.length === 0) {
siretResults.innerHTML = '<p class="text-xs text-gray-400 p-2">Aucun resultat.</p>';
return;

View File

@@ -1213,4 +1213,172 @@ class DevisControllerTest extends TestCase
$this->assertInstanceOf(Response::class, $response);
$this->assertSame(302, $response->getStatusCode());
}
// ── services ──
private function buildControllerWithEm(EntityManagerInterface $em): DevisController
{
$orderNumberService = $this->createStub(\App\Service\OrderNumberService::class);
$devisService = $this->createStub(\App\Service\DevisService::class);
$meilisearch = $this->createStub(\App\Service\MeilisearchService::class);
$controller = new DevisController($em, $orderNumberService, $devisService, $meilisearch);
$session = new Session(new MockArraySessionStorage());
$stack = $this->createStub(RequestStack::class);
$stack->method('getSession')->willReturn($session);
$twig = $this->createStub(Environment::class);
$twig->method('render')->willReturn('<html></html>');
$router = $this->createStub(RouterInterface::class);
$router->method('generate')->willReturn('/redirect');
$container = $this->createStub(ContainerInterface::class);
$container->method('has')->willReturnMap([
['twig', true],
['router', true],
['security.authorization_checker', true],
['security.token_storage', true],
['request_stack', true],
['parameter_bag', true],
['serializer', false],
]);
$container->method('get')->willReturnMap([
['twig', $twig],
['router', $router],
['security.authorization_checker', $this->createStub(AuthorizationCheckerInterface::class)],
['security.token_storage', $this->createStub(TokenStorageInterface::class)],
['request_stack', $stack],
['parameter_bag', $this->createStub(ParameterBagInterface::class)],
]);
$controller->setContainer($container);
return $controller;
}
public function testServicesCustomerNotFound(): void
{
$repo = $this->createStub(\Doctrine\ORM\EntityRepository::class);
$repo->method('find')->willReturn(null);
$em = $this->createStub(EntityManagerInterface::class);
$em->method('getRepository')->willReturn($repo);
$controller = $this->buildControllerWithEm($em);
$response = $controller->services(999, 'ndd');
$this->assertSame(200, $response->getStatusCode());
$this->assertSame('[]', $response->getContent());
}
public function testServicesNdd(): void
{
$customer = $this->createStub(\App\Entity\Customer::class);
$domain = $this->createStub(\App\Entity\Domain::class);
$domain->method('getId')->willReturn(1);
$domain->method('getFqdn')->willReturn('example.com');
$customerRepo = $this->createStub(\Doctrine\ORM\EntityRepository::class);
$customerRepo->method('find')->willReturn($customer);
$domainRepo = $this->createStub(\Doctrine\ORM\EntityRepository::class);
$domainRepo->method('findBy')->willReturn([$domain]);
$em = $this->createStub(EntityManagerInterface::class);
$em->method('getRepository')->willReturnCallback(fn ($class) => match ($class) {
\App\Entity\Customer::class => $customerRepo,
\App\Entity\Domain::class => $domainRepo,
default => $this->createStub(\Doctrine\ORM\EntityRepository::class),
});
$controller = $this->buildControllerWithEm($em);
$response = $controller->services(1, 'ndd');
$data = json_decode($response->getContent(), true);
$this->assertSame(1, $data[0]['id']);
$this->assertSame('example.com', $data[0]['label']);
}
public function testServicesWebsite(): void
{
$customer = $this->createStub(\App\Entity\Customer::class);
$website = $this->createStub(\App\Entity\Website::class);
$website->method('getId')->willReturn(5);
$website->method('getName')->willReturn('Mon Site');
$website->method('getType')->willReturn('vitrine');
$customerRepo = $this->createStub(\Doctrine\ORM\EntityRepository::class);
$customerRepo->method('find')->willReturn($customer);
$websiteRepo = $this->createStub(\Doctrine\ORM\EntityRepository::class);
$websiteRepo->method('findBy')->willReturn([$website]);
$em = $this->createStub(EntityManagerInterface::class);
$em->method('getRepository')->willReturnCallback(fn ($class) => match ($class) {
\App\Entity\Customer::class => $customerRepo,
\App\Entity\Website::class => $websiteRepo,
default => $this->createStub(\Doctrine\ORM\EntityRepository::class),
});
$controller = $this->buildControllerWithEm($em);
$response = $controller->services(1, 'website');
$data = json_decode($response->getContent(), true);
$this->assertSame(5, $data[0]['id']);
$this->assertStringContainsString('Mon Site', $data[0]['label']);
}
public function testServicesEsymail(): void
{
$customer = $this->createStub(\App\Entity\Customer::class);
$domain = $this->createStub(\App\Entity\Domain::class);
$email = $this->createStub(\App\Entity\DomainEmail::class);
$email->method('getId')->willReturn(10);
$email->method('getFullEmail')->willReturn('user@example.com');
$customerRepo = $this->createStub(\Doctrine\ORM\EntityRepository::class);
$customerRepo->method('find')->willReturn($customer);
$domainRepo = $this->createStub(\Doctrine\ORM\EntityRepository::class);
$domainRepo->method('findBy')->willReturn([$domain]);
$emailRepo = $this->createStub(\Doctrine\ORM\EntityRepository::class);
$emailRepo->method('findBy')->willReturn([$email]);
$em = $this->createStub(EntityManagerInterface::class);
$em->method('getRepository')->willReturnCallback(fn ($class) => match ($class) {
\App\Entity\Customer::class => $customerRepo,
\App\Entity\Domain::class => $domainRepo,
\App\Entity\DomainEmail::class => $emailRepo,
default => $this->createStub(\Doctrine\ORM\EntityRepository::class),
});
$controller = $this->buildControllerWithEm($em);
$response = $controller->services(1, 'esymail');
$data = json_decode($response->getContent(), true);
$this->assertSame(10, $data[0]['id']);
$this->assertSame('user@example.com', $data[0]['label']);
}
public function testServicesDefaultType(): void
{
$customer = $this->createStub(\App\Entity\Customer::class);
$customerRepo = $this->createStub(\Doctrine\ORM\EntityRepository::class);
$customerRepo->method('find')->willReturn($customer);
$em = $this->createStub(EntityManagerInterface::class);
$em->method('getRepository')->willReturn($customerRepo);
$controller = $this->buildControllerWithEm($em);
$response = $controller->services(1, 'unknown');
$this->assertSame('[]', $response->getContent());
}
}