diff --git a/tests/Security/IntranetLockedTest.php b/tests/Security/IntranetLockedTest.php index 91449ed..f7027e9 100644 --- a/tests/Security/IntranetLockedTest.php +++ b/tests/Security/IntranetLockedTest.php @@ -13,6 +13,7 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpFoundation\Request; +use Symfony\Contracts\Cache\CacheInterface; use Twig\Environment; #[AllowMockObjectsWithoutExpectations] @@ -23,6 +24,7 @@ class IntranetLockedTest extends TestCase private $searchClient; private $stripeClient; private $mailer; + private $cache; private $listener; protected function setUp(): void @@ -32,13 +34,22 @@ class IntranetLockedTest extends TestCase $this->searchClient = $this->createMock(SearchClient::class); $this->stripeClient = $this->createMock(StripeClient::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->twig, $this->signatureClient, $this->searchClient, $this->stripeClient, - $this->mailer + $this->mailer, + $this->cache ); } @@ -56,7 +67,7 @@ class IntranetLockedTest extends TestCase $response = $event->getResponse(); $this->assertInstanceOf(Response::class, $response); $this->assertEquals(Response::HTTP_FORBIDDEN, $response->getStatusCode()); - + unset($_ENV['INTRANET_LOCK']); } @@ -81,15 +92,21 @@ class IntranetLockedTest extends TestCase $request = new Request(); $event = new RequestEvent($kernel, $request, HttpKernelInterface::MAIN_REQUEST); + // Simulation d'une panne $this->signatureClient->method('status')->willReturn(false); $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); $response = $event->getResponse(); - $this->assertInstanceOf(Response::class, $response); + $this->assertNotNull($response); $this->assertEquals(Response::HTTP_FORBIDDEN, $response->getStatusCode()); } }