test: DevisController search() 100% coverage (3 tests)
- testSearchEmptyQuery, testSearchWhitespaceQuery, testSearchWithResults Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1381,4 +1381,69 @@ class DevisControllerTest extends TestCase
|
|||||||
$response = $controller->services(1, 'unknown');
|
$response = $controller->services(1, 'unknown');
|
||||||
$this->assertSame('[]', $response->getContent());
|
$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']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user