feat(test): Ajoute le cache et teste la panne du service Signature.

This commit is contained in:
Serreau Jovann
2026-01-31 14:07:26 +01:00
parent 970a47bcc4
commit 18ac532914

View File

@@ -13,6 +13,7 @@ use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Contracts\Cache\CacheInterface;
use Twig\Environment; use Twig\Environment;
#[AllowMockObjectsWithoutExpectations] #[AllowMockObjectsWithoutExpectations]
@@ -23,6 +24,7 @@ class IntranetLockedTest extends TestCase
private $searchClient; private $searchClient;
private $stripeClient; private $stripeClient;
private $mailer; private $mailer;
private $cache;
private $listener; private $listener;
protected function setUp(): void protected function setUp(): void
@@ -32,13 +34,22 @@ class IntranetLockedTest extends TestCase
$this->searchClient = $this->createMock(SearchClient::class); $this->searchClient = $this->createMock(SearchClient::class);
$this->stripeClient = $this->createMock(StripeClient::class); $this->stripeClient = $this->createMock(StripeClient::class);
$this->mailer = $this->createMock(Mailer::class); $this->mailer = $this->createMock(Mailer::class);
$this->cache = $this->createMock(CacheInterface::class);
// Configuration par défaut du mock de cache :
// Il exécute immédiatement le callback passé en argument (le 2ème paramètre de get())
$this->cache->method('get')->willReturnCallback(function ($key, $callback) {
$item = $this->createMock(\Symfony\Contracts\Cache\ItemInterface::class);
return $callback($item);
});
$this->listener = new IntranetLocked( $this->listener = new IntranetLocked(
$this->twig, $this->twig,
$this->signatureClient, $this->signatureClient,
$this->searchClient, $this->searchClient,
$this->stripeClient, $this->stripeClient,
$this->mailer $this->mailer,
$this->cache
); );
} }
@@ -56,7 +67,7 @@ class IntranetLockedTest extends TestCase
$response = $event->getResponse(); $response = $event->getResponse();
$this->assertInstanceOf(Response::class, $response); $this->assertInstanceOf(Response::class, $response);
$this->assertEquals(Response::HTTP_FORBIDDEN, $response->getStatusCode()); $this->assertEquals(Response::HTTP_FORBIDDEN, $response->getStatusCode());
unset($_ENV['INTRANET_LOCK']); unset($_ENV['INTRANET_LOCK']);
} }
@@ -81,15 +92,21 @@ class IntranetLockedTest extends TestCase
$request = new Request(); $request = new Request();
$event = new RequestEvent($kernel, $request, HttpKernelInterface::MAIN_REQUEST); $event = new RequestEvent($kernel, $request, HttpKernelInterface::MAIN_REQUEST);
// Simulation d'une panne
$this->signatureClient->method('status')->willReturn(false); $this->signatureClient->method('status')->willReturn(false);
$this->mailer->expects($this->once())->method('send'); $this->mailer->expects($this->once())->method('send');
$this->twig->expects($this->once())->method('render')->with('security/error.twig')->willReturn('Error'); $this->twig->expects($this->once())
->method('render')
->with('security/error.twig', $this->callback(function($subject) {
return $subject['message']['service'] === 'Signature';
}))
->willReturn('Error');
$this->listener->onControl($event); $this->listener->onControl($event);
$response = $event->getResponse(); $response = $event->getResponse();
$this->assertInstanceOf(Response::class, $response); $this->assertNotNull($response);
$this->assertEquals(Response::HTTP_FORBIDDEN, $response->getStatusCode()); $this->assertEquals(Response::HTTP_FORBIDDEN, $response->getStatusCode());
} }
} }