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:
@@ -690,6 +690,74 @@ class AccountControllerTest extends WebTestCase
|
||||
self::assertResponseRedirects('/mon-compte/evenement/'.$event->getId().'/modifier');
|
||||
}
|
||||
|
||||
public function testCreateEventWithPicture(): void
|
||||
{
|
||||
$client = static::createClient();
|
||||
$user = $this->createUser(['ROLE_ORGANIZER'], true);
|
||||
|
||||
$client->loginUser($user);
|
||||
|
||||
$picture = new \Symfony\Component\HttpFoundation\File\UploadedFile(
|
||||
__DIR__.'/../../public/logo.png',
|
||||
'affiche.png',
|
||||
'image/png',
|
||||
null,
|
||||
true,
|
||||
);
|
||||
|
||||
$client->request('POST', '/mon-compte/evenement/creer', [
|
||||
'title' => 'Event With Picture',
|
||||
'description' => 'Description',
|
||||
'start_at' => '2026-09-01T10:00',
|
||||
'end_at' => '2026-09-01T18:00',
|
||||
'address' => '1 rue test',
|
||||
'zipcode' => '75001',
|
||||
'city' => 'Paris',
|
||||
], ['event_main_picture' => $picture]);
|
||||
|
||||
self::assertResponseRedirects('/mon-compte?tab=events');
|
||||
}
|
||||
|
||||
public function testEditEventWithPicture(): void
|
||||
{
|
||||
$client = static::createClient();
|
||||
$em = static::getContainer()->get(EntityManagerInterface::class);
|
||||
$user = $this->createUser(['ROLE_ORGANIZER'], true);
|
||||
|
||||
$event = new \App\Entity\Event();
|
||||
$event->setAccount($user);
|
||||
$event->setTitle('Edit With Pic');
|
||||
$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');
|
||||
$em->persist($event);
|
||||
$em->flush();
|
||||
|
||||
$client->loginUser($user);
|
||||
|
||||
$picture = new \Symfony\Component\HttpFoundation\File\UploadedFile(
|
||||
__DIR__.'/../../public/logo.png',
|
||||
'affiche.png',
|
||||
'image/png',
|
||||
null,
|
||||
true,
|
||||
);
|
||||
|
||||
$client->request('POST', '/mon-compte/evenement/'.$event->getId().'/modifier', [
|
||||
'title' => 'Edited With Pic',
|
||||
'description' => 'New desc',
|
||||
'start_at' => '2026-09-01T10:00',
|
||||
'end_at' => '2026-09-01T18:00',
|
||||
'address' => '2 rue',
|
||||
'zipcode' => '69001',
|
||||
'city' => 'Lyon',
|
||||
], ['event_main_picture' => $picture]);
|
||||
|
||||
self::assertResponseRedirects('/mon-compte?tab=events');
|
||||
}
|
||||
|
||||
public function testEventsSearchReturnsSuccess(): void
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
@@ -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