Reduce cognitive complexity, improve test coverage, fix SonarQube issues

Cognitive complexity refactors:
- cart.js: extract buildCart, handleCheckout, updateStockLabel, updateItemStock, startStockPolling (21→~8)
- tabs.js: use .at(-1) instead of [length-1]
- MeilisearchConsistencyCommand: extract checkAllIndexes, accumulate, reportSummary (18→~8)
- TranslateCommand: extract processDomain, processLanguage, loadExisting, findMissingKeys, removeObsoleteKeys, handleUpToDate, mergeAndOrder (36→~10)
- AccountController::index: extract computeFinanceStats with statusMap pattern (19→~12)

Test coverage additions:
- HomeController: expired invitation view, stock not found, stock with billets, search+city with mock results
- AdminController: delete/resend invitation not found (404)
- AccountController: item without billet (codeCoverageIgnore - NOT NULL in DB)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Serreau Jovann
2026-03-23 12:57:00 +01:00
parent 1eba8b41ee
commit 09a3e7867e
8 changed files with 435 additions and 220 deletions

View File

@@ -817,6 +817,28 @@ class AdminControllerTest extends WebTestCase
self::assertSame(\App\Entity\OrganizerInvitation::STATUS_SENT, $updated->getStatus());
}
public function testDeleteInvitationNotFound(): void
{
$client = static::createClient();
$admin = $this->createUser(['ROLE_ROOT']);
$client->loginUser($admin);
$client->request('POST', '/admin/organisateurs/invitation/999999/supprimer');
self::assertResponseStatusCodeSame(404);
}
public function testResendInvitationNotFound(): void
{
$client = static::createClient();
$admin = $this->createUser(['ROLE_ROOT']);
$client->loginUser($admin);
$client->request('POST', '/admin/organisateurs/invitation/999999/renvoyer');
self::assertResponseStatusCodeSame(404);
}
public function testExportCsv(): void
{
$client = static::createClient();

View File

@@ -177,6 +177,43 @@ class HomeControllerTest extends WebTestCase
self::assertResponseIsSuccessful();
}
public function testEventsPageWithSearchAndCityMatchingResults(): void
{
$client = static::createClient();
$em = static::getContainer()->get(EntityManagerInterface::class);
$user = new User();
$user->setEmail('test-events-search-'.uniqid().'@example.com');
$user->setFirstName('Search');
$user->setLastName('Test');
$user->setPassword('hashed');
$user->setRoles(['ROLE_ORGANIZER']);
$user->setIsApproved(true);
$user->setIsVerified(true);
$em->persist($user);
$event = new \App\Entity\Event();
$event->setAccount($user);
$event->setTitle('Brocante Geante');
$event->setStartAt(new \DateTimeImmutable('2026-08-01 10:00'));
$event->setEndAt(new \DateTimeImmutable('2026-08-01 18:00'));
$event->setAddress('1 rue');
$event->setZipcode('75001');
$event->setCity('Paris');
$event->setIsOnline(true);
$em->persist($event);
$em->flush();
// Mock EventIndexService to return the event (simulates Meilisearch match)
$eventIndex = $this->createMock(\App\Service\EventIndexService::class);
$eventIndex->method('searchEvents')->willReturn([$event]);
static::getContainer()->set(\App\Service\EventIndexService::class, $eventIndex);
$client->request('GET', '/evenements?q=Brocante&city=Paris');
self::assertResponseIsSuccessful();
}
public function testEventStockRoute(): void
{
$client = static::createClient();
@@ -202,10 +239,34 @@ class HomeControllerTest extends WebTestCase
$event->setCity('Paris');
$event->setIsOnline(true);
$em->persist($event);
$category = new \App\Entity\Category();
$category->setName('Cat Stock');
$category->setEvent($event);
$em->persist($category);
$billet = new \App\Entity\Billet();
$billet->setName('Entree');
$billet->setCategory($category);
$billet->setPriceHT(1000);
$billet->setQuantity(50);
$em->persist($billet);
$em->flush();
$client->request('GET', '/evenement/'.$event->getId().'/stock');
self::assertResponseIsSuccessful();
$data = json_decode($client->getResponse()->getContent(), true);
self::assertSame(50, $data[$billet->getId()]);
}
public function testEventStockNotFound(): void
{
$client = static::createClient();
$client->request('GET', '/evenement/999999/stock');
self::assertResponseIsSuccessful();
self::assertSame('[]', $client->getResponse()->getContent());
}
public function testEventDetailNotFoundReturns404(): void

View File

@@ -68,6 +68,21 @@ class InvitationFlowTest extends WebTestCase
self::assertSame(OrganizerInvitation::STATUS_OPENED, $invitation->getStatus());
}
public function testViewExpiredInvitation(): void
{
$client = static::createClient();
$em = static::getContainer()->get(EntityManagerInterface::class);
$invitation = $this->createInvitation($em);
$ref = new \ReflectionProperty($invitation, 'createdAt');
$ref->setValue($invitation, new \DateTimeImmutable('-10 days'));
$em->flush();
$client->request('GET', '/invitation/'.$invitation->getToken());
self::assertResponseIsSuccessful();
self::assertStringContainsString('expiree', $client->getResponse()->getContent());
}
public function testViewInvitationInvalidTokenReturns404(): void
{
$client = static::createClient();