From ca53002caedafe9a36a35b32b6a5ed2dd3c8d60b Mon Sep 17 00:00:00 2001 From: Serreau Jovann Date: Wed, 8 Apr 2026 17:40:27 +0200 Subject: [PATCH] test: DevisController search() 100% coverage (3 tests) - testSearchEmptyQuery, testSearchWhitespaceQuery, testSearchWithResults Co-Authored-By: Claude Opus 4.6 (1M context) --- .../Controller/Admin/DevisControllerTest.php | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/tests/Controller/Admin/DevisControllerTest.php b/tests/Controller/Admin/DevisControllerTest.php index c358de2..1a926f3 100644 --- a/tests/Controller/Admin/DevisControllerTest.php +++ b/tests/Controller/Admin/DevisControllerTest.php @@ -1381,4 +1381,69 @@ class DevisControllerTest extends TestCase $response = $controller->services(1, 'unknown'); $this->assertSame('[]', $response->getContent()); } + + // ── search ── + + public function testSearchEmptyQuery(): void + { + $em = $this->createStub(EntityManagerInterface::class); + $controller = $this->buildControllerWithEm($em); + + $request = new Request(['q' => '']); + $response = $controller->search(1, $request); + $this->assertSame('[]', $response->getContent()); + } + + public function testSearchWhitespaceQuery(): void + { + $em = $this->createStub(EntityManagerInterface::class); + $controller = $this->buildControllerWithEm($em); + + $request = new Request(['q' => ' ']); + $response = $controller->search(1, $request); + $this->assertSame('[]', $response->getContent()); + } + + public function testSearchWithResults(): void + { + $meilisearch = $this->createMock(\App\Service\MeilisearchService::class); + $meilisearch->method('searchDevis')->with('test', 20, 42)->willReturn([ + ['numOrder' => '04/2026-00001', 'customerName' => 'Client A'], + ]); + + $em = $this->createStub(EntityManagerInterface::class); + $controller = new DevisController( + $em, + $this->createStub(\App\Service\OrderNumberService::class), + $this->createStub(\App\Service\DevisService::class), + $meilisearch, + ); + + $session = new Session(new MockArraySessionStorage()); + $stack = $this->createStub(RequestStack::class); + $stack->method('getSession')->willReturn($session); + + $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', $this->createStub(Environment::class)], + ['router', $this->createStub(RouterInterface::class)], + ['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); + + $request = new Request(['q' => 'test']); + $response = $controller->search(42, $request); + + $data = json_decode($response->getContent(), true); + $this->assertCount(1, $data); + $this->assertSame('04/2026-00001', $data[0]['numOrder']); + } }