public function testConfigureNoRequest()
 {
     $response = new Response();
     $expected_response = clone $response;
     $this->request_stack->expects($this->once())->method('getMasterRequest')->will($this->returnValue(null));
     $configurator = new ResponseConfigurator($this->key_builder, $this->request_stack, []);
     $this->assertEquals($expected_response, $configurator->configure($response, new \DateTime(), -1));
 }
 /**
  * Get cache response.
  *
  * Set $lifetime as < 0 for not set max-age
  *
  * @param mixed $params
  * @param int $lifetime
  * @param Response|null $response
  *
  * @return Response
  */
 public function getResponse($params = [], $lifetime = -1, Response $response = null)
 {
     if (!$response) {
         $response = new Response();
     }
     if (!$this->enable) {
         return $response;
     }
     return $this->configurator->configure($response, $this->getMax($params), $lifetime);
 }
 public function testGetModifiedResponse()
 {
     $this->driver->expects($this->once())->method('getMax')->with(['foo', Keeper::LAST_UPDATE_KEY])->will($this->returnValue($this->time));
     /** @var $request \PHPUnit_Framework_MockObject_MockObject|Request */
     $request = $this->getMock(Request::class);
     /** @var $response \PHPUnit_Framework_MockObject_MockObject|Response */
     $response = $this->getMock(Response::class);
     /** @var $configured_response \PHPUnit_Framework_MockObject_MockObject|Response */
     $configured_response = $this->getMock(Response::class);
     $configured_response->expects($this->once())->method('isNotModified')->with($request)->will($this->returnValue(true));
     $configured_response->expects($this->atLeastOnce())->method('getStatusCode')->will($this->returnValue(Response::HTTP_NOT_MODIFIED));
     $this->configurator->expects($this->once())->method('configure')->with($response, $this->time)->will($this->returnValue($configured_response));
     try {
         $this->keeper->getModifiedResponse($request, 'foo', -1, $response);
         $this->assertTrue(false, 'Must throw exception');
     } catch (NotModifiedException $e) {
         $this->assertEquals($configured_response, $e->getResponse());
         $this->assertEquals(Response::HTTP_NOT_MODIFIED, $e->getCode());
         $this->assertEquals(Response::$statusTexts[Response::HTTP_NOT_MODIFIED], $e->getMessage());
     }
 }