public function testContentIsLoadedFromCacheAndSetOnResponse()
 {
     $expectedResponse = new HttpResponse();
     $expectedResponse->setContent('mockContent');
     $this->cacheServiceMock->shouldReceive('load')->once()->andReturn('mockContent');
     $this->cacheServiceMock->shouldReceive('save')->never();
     $mvcEvent = $this->createMvcEvent();
     $this->cacheListener->getOptions()->setCacheResponse(false);
     $response = $this->cacheListener->onRoute($mvcEvent);
     $this->assertEquals($expectedResponse->getContent(), $response->getContent());
     $this->cacheListener->onFinish($mvcEvent);
 }
Пример #2
0
 /**
  * Запись логов
  * @param Request $request
  * @param Response $response
  */
 public function write($request, $response)
 {
     $serverOptions = $request->getServer()->toArray();
     $requestUri = isset($serverOptions['REQUEST_URI']) ? $serverOptions['REQUEST_URI'] : null;
     // Проверка на запись от правильного запроса
     if (is_null($requestUri) || !preg_match($this->_patternRequestWriteLog, $requestUri)) {
         return;
     }
     $remoteAddr = isset($serverOptions['REMOTE_ADDR']) ? $serverOptions['REMOTE_ADDR'] : '';
     $requestTime = isset($serverOptions['REQUEST_TIME']) ? $serverOptions['REQUEST_TIME'] : 0;
     $requestTimeFloat = isset($serverOptions['REQUEST_TIME_FLOAT']) ? $serverOptions['REQUEST_TIME_FLOAT'] : 0;
     /** @var DocumentManager $dm */
     $dm = $this->getServiceLocator()->get('doctrine-document');
     $logsClient = new LogsClient();
     $logsClient->setDatetime((new \DateTime())->setTimestamp($requestTime))->setHeaders($request->getHeaders()->toString())->setRequest($request->getContent())->setResponse($response->getContent())->setIpAddress($remoteAddr)->setDuration(round(microtime(true), 4) - $requestTimeFloat);
     $dm->persist($logsClient);
     $dm->flush();
 }