Add coverage tests: event picture upload (create/edit), searchEvents fallback/empty/results/no-hits

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Serreau Jovann
2026-03-20 21:47:38 +01:00
parent 8d062cfd36
commit e0d12ba874
2 changed files with 129 additions and 0 deletions

View File

@@ -146,4 +146,65 @@ class EventIndexServiceTest extends TestCase
$this->service->removeEvent($event);
}
public function testSearchEventsFallsBackOnException(): void
{
$this->meilisearch->method('search')
->willThrowException(new \RuntimeException('Meilisearch down'));
$repo = $this->createMock(\Doctrine\ORM\EntityRepository::class);
$repo->method('findBy')->willReturn([]);
$em = $this->createMock(EntityManagerInterface::class);
$em->method('getRepository')->willReturn($repo);
$service = new EventIndexService($this->meilisearch, $em);
$result = $service->searchEvents('event_global', 'test', ['isOnline' => true]);
self::assertIsArray($result);
}
public function testSearchEventsEmptyQueryReturnsFallback(): void
{
$repo = $this->createMock(\Doctrine\ORM\EntityRepository::class);
$repo->method('findBy')->willReturn([]);
$em = $this->createMock(EntityManagerInterface::class);
$em->method('getRepository')->willReturn($repo);
$service = new EventIndexService($this->meilisearch, $em);
$result = $service->searchEvents('event_global', '', ['isOnline' => true]);
self::assertIsArray($result);
}
public function testSearchEventsWithResults(): void
{
$this->meilisearch->method('search')
->willReturn(['hits' => [['id' => 1], ['id' => 2]]]);
$repo = $this->createMock(\Doctrine\ORM\EntityRepository::class);
$repo->method('findBy')->willReturn([]);
$em = $this->createMock(EntityManagerInterface::class);
$em->method('getRepository')->willReturn($repo);
$service = new EventIndexService($this->meilisearch, $em);
$result = $service->searchEvents('event_global', 'brocante');
self::assertIsArray($result);
}
public function testSearchEventsNoHits(): void
{
$this->meilisearch->method('search')
->willReturn(['hits' => []]);
$em = $this->createMock(EntityManagerInterface::class);
$service = new EventIndexService($this->meilisearch, $em);
$result = $service->searchEvents('event_global', 'zzzzz');
self::assertEmpty($result);
}
}