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:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user