twig = $this->createMock(Environment::class); $this->signatureClient = $this->createMock(SignatureClient::class); $this->searchClient = $this->createMock(SearchClient::class); $this->stripeClient = $this->createMock(StripeClient::class); $this->mailer = $this->createMock(Mailer::class); $this->listener = new IntranetLocked( $this->twig, $this->signatureClient, $this->searchClient, $this->stripeClient, $this->mailer ); } public function testOnLockedWhenEnabled() { $_ENV['INTRANET_LOCK'] = 'true'; $kernel = $this->createMock(HttpKernelInterface::class); $request = new Request(); $event = new RequestEvent($kernel, $request, HttpKernelInterface::MAIN_REQUEST); $this->twig->expects($this->once())->method('render')->with('security/locked.twig')->willReturn('Locked'); $this->listener->onLocked($event); $response = $event->getResponse(); $this->assertInstanceOf(Response::class, $response); $this->assertEquals(Response::HTTP_FORBIDDEN, $response->getStatusCode()); unset($_ENV['INTRANET_LOCK']); } public function testOnControlAllServicesUp() { $kernel = $this->createMock(HttpKernelInterface::class); $request = new Request(); $event = new RequestEvent($kernel, $request, HttpKernelInterface::MAIN_REQUEST); $this->signatureClient->method('status')->willReturn(true); $this->searchClient->method('status')->willReturn(true); $this->stripeClient->method('status')->willReturn(true); $this->listener->onControl($event); $this->assertNull($event->getResponse()); } public function testOnControlServiceDown() { $kernel = $this->createMock(HttpKernelInterface::class); $request = new Request(); $event = new RequestEvent($kernel, $request, HttpKernelInterface::MAIN_REQUEST); $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->listener->onControl($event); $response = $event->getResponse(); $this->assertInstanceOf(Response::class, $response); $this->assertEquals(Response::HTTP_FORBIDDEN, $response->getStatusCode()); } }