test: couverture 100% ClientsController et Customer après ajout APE/RNA

CustomerTest :
- testLegal : ajout assertions setApe/getApe ('62.01Z') et setRna/getRna ('W502004724')

ClientsControllerTest (3 tests ajoutés) :
- testEntrepriseSearchTooShort : query < 2 chars retourne results vide
- testEntrepriseSearchSuccess : proxy API retourne résultats avec SIREN
- testEntrepriseSearchApiError : API down retourne 502 avec message erreur

Résultat : ClientsController 100% (7/7, 68/68), Customer 100% (44/44, 76/76)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Serreau Jovann
2026-04-04 11:08:41 +02:00
parent ec0c0366c4
commit 5369682f35
2 changed files with 42 additions and 0 deletions

View File

@@ -8,6 +8,8 @@ use App\Entity\User;
use App\Repository\CustomerRepository;
use App\Service\MeilisearchService;
use App\Service\UserManagementService;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Contracts\HttpClient\ResponseInterface;
use Doctrine\ORM\EntityManagerInterface;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
@@ -143,6 +145,42 @@ class ClientsControllerTest extends TestCase
$this->assertStringContainsString('John Doe', $response->getContent());
}
public function testEntrepriseSearchTooShort(): void
{
$controller = new ClientsController();
$request = new Request(['q' => 'a']);
$response = $controller->entrepriseSearch($request, $this->createStub(HttpClientInterface::class));
$this->assertInstanceOf(JsonResponse::class, $response);
$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);
$controller = new ClientsController();
$request = new Request(['q' => 'siteconseil']);
$response = $controller->entrepriseSearch($request, $httpClient);
$this->assertInstanceOf(JsonResponse::class, $response);
$this->assertStringContainsString('123456789', $response->getContent());
}
public function testEntrepriseSearchApiError(): void
{
$httpClient = $this->createStub(HttpClientInterface::class);
$httpClient->method('request')->willThrowException(new \RuntimeException('API down'));
$controller = new ClientsController();
$request = new Request(['q' => 'test']);
$response = $controller->entrepriseSearch($request, $httpClient);
$this->assertSame(502, $response->getStatusCode());
$this->assertStringContainsString('Service indisponible', $response->getContent());
}
public function testToggle(): void
{
$user = new User();

View File

@@ -117,9 +117,13 @@ class CustomerTest extends TestCase
$c->setSiret('12345678901234');
$c->setRcs('RCS Paris');
$c->setNumTva('FR12345678901');
$c->setApe('62.01Z');
$c->setRna('W502004724');
$this->assertSame('12345678901234', $c->getSiret());
$this->assertSame('RCS Paris', $c->getRcs());
$this->assertSame('FR12345678901', $c->getNumTva());
$this->assertSame('62.01Z', $c->getApe());
$this->assertSame('W502004724', $c->getRna());
}
public function testStripe(): void