Add test coverage for remaining controllers, fix label accessibility, refactor duplicated code

New tests (47 added, 622 total):
- MonitorMessengerCommand: no failures, failures with email, null error, multiple (4)
- UnsubscribeController: unsubscribe with invitations refused + admin notified (1)
- AdminController: suspend/reactivate orga, orders page with filters, logs, invite orga submit/empty, delete/resend invitation, export CSV/PDF (13)
- AccountController: export CSV/PDF, getAllowedBilletTypes (free/basic/sur-mesure/null), billet type restriction, finance stats all statuses, soldCounts (9)
- HomeController: city filter, date filter, all filters combined, stock route (4)
- OrderController: event ended, invalid cart JSON, invalid email, stock zero (4)
- MailerService: getAdminEmail, getAdminFrom (2)
- JS: comment node, tabs missing panel/id/parent, cart stock polling edge cases (10)

Accessibility fixes:
- events.html.twig: add for/id on search, city, date labels
- admin/orders.html.twig: add for/id on search, status labels

Code quality:
- cart.js: remove dead ternaire branch (max > 10 always plural)
- tabs.js: use optional chaining for tablist?.setAttribute
- MeilisearchConsistencyCommand: extract diffAndReport() (was duplicated 3x)
- Email templates: extract _order_items_table.html.twig partial
- SonarQube: exclude src/Entity/** from CPD

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Serreau Jovann
2026-03-23 12:11:07 +01:00
parent 42d06dd49f
commit c2ebd291b8
10 changed files with 518 additions and 14 deletions

View File

@@ -0,0 +1,129 @@
<?php
namespace App\Tests\Command;
use App\Command\MonitorMessengerCommand;
use App\Entity\MessengerLog;
use App\Service\MailerService;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;
class MonitorMessengerCommandTest extends TestCase
{
private EntityManagerInterface $em;
private MailerService $mailer;
private CommandTester $tester;
protected function setUp(): void
{
$this->em = $this->createMock(EntityManagerInterface::class);
$this->mailer = $this->createMock(MailerService::class);
$command = new MonitorMessengerCommand($this->em, $this->mailer);
$app = new Application();
$app->addCommand($command);
$this->tester = new CommandTester($app->find('app:monitor:messenger'));
}
public function testNoFailedMessages(): void
{
$repo = $this->createMock(EntityRepository::class);
$repo->method('findBy')->willReturn([]);
$this->em->method('getRepository')
->with(MessengerLog::class)
->willReturn($repo);
$this->mailer->expects(self::never())->method('sendEmail');
$this->tester->execute([]);
self::assertSame(0, $this->tester->getStatusCode());
self::assertStringContainsString('No failed messages', $this->tester->getDisplay());
}
public function testFailedMessagesSendsEmail(): void
{
$log = $this->createMock(MessengerLog::class);
$log->method('getMessageClass')->willReturn('App\\Message\\TestMessage');
$log->method('getCreatedAt')->willReturn(new \DateTimeImmutable('2026-03-23 10:00'));
$log->method('getErrorMessage')->willReturn('Something went wrong');
$repo = $this->createMock(EntityRepository::class);
$repo->method('findBy')->willReturn([$log]);
$this->em->method('getRepository')
->with(MessengerLog::class)
->willReturn($repo);
$this->mailer->method('getAdminEmail')->willReturn('admin@test.com');
$this->mailer->expects(self::once())->method('sendEmail')->with(
'admin@test.com',
'[E-Ticket] 1 message(s) Messenger en echec',
$this->callback(fn (string $html) => str_contains($html, 'TestMessage') && str_contains($html, 'Something went wrong')),
null,
null,
false,
);
$this->tester->execute([]);
self::assertSame(0, $this->tester->getStatusCode());
self::assertStringContainsString('1 failed message(s)', $this->tester->getDisplay());
self::assertStringContainsString('admin@test.com', $this->tester->getDisplay());
}
public function testFailedMessageWithNullError(): void
{
$log = $this->createMock(MessengerLog::class);
$log->method('getMessageClass')->willReturn('App\\Message\\Other');
$log->method('getCreatedAt')->willReturn(new \DateTimeImmutable());
$log->method('getErrorMessage')->willReturn(null);
$repo = $this->createMock(EntityRepository::class);
$repo->method('findBy')->willReturn([$log]);
$this->em->method('getRepository')->willReturn($repo);
$this->mailer->method('getAdminEmail')->willReturn('admin@test.com');
$this->mailer->expects(self::once())->method('sendEmail');
$this->tester->execute([]);
self::assertSame(0, $this->tester->getStatusCode());
}
public function testMultipleFailedMessages(): void
{
$logs = [];
for ($i = 0; $i < 3; ++$i) {
$log = $this->createMock(MessengerLog::class);
$log->method('getMessageClass')->willReturn('Msg'.$i);
$log->method('getCreatedAt')->willReturn(new \DateTimeImmutable());
$log->method('getErrorMessage')->willReturn('Error '.$i);
$logs[] = $log;
}
$repo = $this->createMock(EntityRepository::class);
$repo->method('findBy')->willReturn($logs);
$this->em->method('getRepository')->willReturn($repo);
$this->mailer->method('getAdminEmail')->willReturn('admin@test.com');
$this->mailer->expects(self::once())->method('sendEmail')->with(
'admin@test.com',
'[E-Ticket] 3 message(s) Messenger en echec',
$this->anything(),
null,
null,
false,
);
$this->tester->execute([]);
self::assertStringContainsString('3 failed message(s)', $this->tester->getDisplay());
}
}