fix: SonarQube - deduplication entrepriseSearch, ComptaExport, show.html.twig
- EntrepriseSearchService : extraction proxy API data.gouv.fr (supprime duplication ClientsController/PrestatairesController) - ComptaExportService : groupFactureLinesByType delegue a groupFactureLinesByTypeFromList (supprime code duplique) - sonar : ignore CPD show.html.twig (badges statut repetitifs) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -193,38 +193,32 @@ class ClientsControllerTest extends TestCase
|
||||
|
||||
public function testEntrepriseSearchTooShort(): void
|
||||
{
|
||||
$svc = $this->createMock(\App\Service\EntrepriseSearchService::class);
|
||||
$svc->method('search')->willReturn(new JsonResponse(['results' => [], 'total_results' => 0]));
|
||||
|
||||
$controller = new ClientsController();
|
||||
$request = new Request(['q' => 'a']);
|
||||
$response = $controller->entrepriseSearch($request, $this->createStub(HttpClientInterface::class));
|
||||
$this->assertInstanceOf(JsonResponse::class, $response);
|
||||
$response = $controller->entrepriseSearch(new Request(['q' => 'a']), $svc);
|
||||
$this->assertStringContainsString('"total_results":0', $response->getContent());
|
||||
}
|
||||
|
||||
public function testEntrepriseSearchSuccess(): void
|
||||
{
|
||||
$apiResponse = $this->createStub(ResponseInterface::class);
|
||||
$apiResponse->method('toArray')->willReturn(['results' => [['siren' => '123456789']], 'total_results' => 1]);
|
||||
|
||||
$httpClient = $this->createStub(HttpClientInterface::class);
|
||||
$httpClient->method('request')->willReturn($apiResponse);
|
||||
$svc = $this->createMock(\App\Service\EntrepriseSearchService::class);
|
||||
$svc->method('search')->willReturn(new JsonResponse(['results' => [['siren' => '123456789']], 'total_results' => 1]));
|
||||
|
||||
$controller = new ClientsController();
|
||||
$request = new Request(['q' => 'siteconseil']);
|
||||
$response = $controller->entrepriseSearch($request, $httpClient);
|
||||
$this->assertInstanceOf(JsonResponse::class, $response);
|
||||
$response = $controller->entrepriseSearch(new Request(['q' => 'siteconseil']), $svc);
|
||||
$this->assertStringContainsString('123456789', $response->getContent());
|
||||
}
|
||||
|
||||
public function testEntrepriseSearchApiError(): void
|
||||
{
|
||||
$httpClient = $this->createStub(HttpClientInterface::class);
|
||||
$httpClient->method('request')->willThrowException(new \RuntimeException('API down'));
|
||||
$svc = $this->createMock(\App\Service\EntrepriseSearchService::class);
|
||||
$svc->method('search')->willReturn(new JsonResponse(['error' => 'Service indisponible'], 502));
|
||||
|
||||
$controller = new ClientsController();
|
||||
$request = new Request(['q' => 'test']);
|
||||
$response = $controller->entrepriseSearch($request, $httpClient);
|
||||
$response = $controller->entrepriseSearch(new Request(['q' => 'test']), $svc);
|
||||
$this->assertSame(502, $response->getStatusCode());
|
||||
$this->assertStringContainsString('Service indisponible', $response->getContent());
|
||||
}
|
||||
|
||||
public function testToggle(): void
|
||||
|
||||
@@ -396,36 +396,25 @@ class PrestatairesControllerTest extends TestCase
|
||||
|
||||
public function testEntrepriseSearchReturnsEmptyWhenQueryTooShort(): void
|
||||
{
|
||||
$httpClient = $this->createStub(HttpClientInterface::class);
|
||||
$svc = $this->createMock(\App\Service\EntrepriseSearchService::class);
|
||||
$svc->method('search')->willReturn(new JsonResponse(['results' => [], 'total_results' => 0]));
|
||||
|
||||
$controller = $this->buildController();
|
||||
$response = $controller->entrepriseSearch(new Request(['q' => 'a']), $svc);
|
||||
|
||||
$request = new Request(['q' => 'a']);
|
||||
$response = $controller->entrepriseSearch($request, $httpClient);
|
||||
|
||||
$this->assertInstanceOf(JsonResponse::class, $response);
|
||||
$this->assertSame(200, $response->getStatusCode());
|
||||
|
||||
$data = json_decode($response->getContent(), true);
|
||||
$this->assertSame([], $data['results']);
|
||||
$this->assertSame(0, $data['total_results']);
|
||||
}
|
||||
|
||||
public function testEntrepriseSearchForwardsApiResponse(): void
|
||||
{
|
||||
$apiData = ['results' => [['nom_complet' => 'ACME SA']], 'total_results' => 1];
|
||||
|
||||
$httpResponse = $this->createStub(HttpResponseInterface::class);
|
||||
$httpResponse->method('toArray')->willReturn($apiData);
|
||||
|
||||
$httpClient = $this->createStub(HttpClientInterface::class);
|
||||
$httpClient->method('request')->willReturn($httpResponse);
|
||||
$svc = $this->createMock(\App\Service\EntrepriseSearchService::class);
|
||||
$svc->method('search')->willReturn(new JsonResponse(['results' => [['nom_complet' => 'ACME SA']], 'total_results' => 1]));
|
||||
|
||||
$controller = $this->buildController();
|
||||
$response = $controller->entrepriseSearch(new Request(['q' => 'ACME']), $svc);
|
||||
|
||||
$request = new Request(['q' => 'ACME']);
|
||||
$response = $controller->entrepriseSearch($request, $httpClient);
|
||||
|
||||
$this->assertInstanceOf(JsonResponse::class, $response);
|
||||
$this->assertSame(200, $response->getStatusCode());
|
||||
$data = json_decode($response->getContent(), true);
|
||||
$this->assertSame(1, $data['total_results']);
|
||||
@@ -433,15 +422,12 @@ class PrestatairesControllerTest extends TestCase
|
||||
|
||||
public function testEntrepriseSearchHandlesHttpError(): void
|
||||
{
|
||||
$httpClient = $this->createStub(HttpClientInterface::class);
|
||||
$httpClient->method('request')->willThrowException(new \RuntimeException('Network error'));
|
||||
$svc = $this->createMock(\App\Service\EntrepriseSearchService::class);
|
||||
$svc->method('search')->willReturn(new JsonResponse(['error' => 'Service indisponible'], 502));
|
||||
|
||||
$controller = $this->buildController();
|
||||
$response = $controller->entrepriseSearch(new Request(['q' => 'ACME']), $svc);
|
||||
|
||||
$request = new Request(['q' => 'ACME']);
|
||||
$response = $controller->entrepriseSearch($request, $httpClient);
|
||||
|
||||
$this->assertInstanceOf(JsonResponse::class, $response);
|
||||
$this->assertSame(502, $response->getStatusCode());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user