Example #1
0
 /**
  * @dataProvider getResponses
  *
  * @param \DateTime $last_modified
  * @param int $max_age
  */
 public function testOnKernelResponse(\DateTime $last_modified = null, $max_age)
 {
     $response = $this->getMock('\\Symfony\\Component\\HttpFoundation\\Response');
     $response->expects($this->once())->method('setPublic');
     $response->expects($this->once())->method('setPublic');
     $response->expects($this->once())->method('getLastModified')->will($this->returnValue($last_modified));
     $response->expects($last_modified ? $this->once() : $this->never())->method('getMaxAge')->will($this->returnValue($max_age));
     /* @var $event \PHPUnit_Framework_MockObject_MockObject|FilterResponseEvent */
     $event = $this->getMockBuilder('\\Symfony\\Component\\HttpKernel\\Event\\FilterResponseEvent')->disableOriginalConstructor()->getMock();
     $event->expects($this->once())->method('getRequestType')->will($this->returnValue(HttpKernelInterface::MASTER_REQUEST));
     $event->expects($this->atLeastOnce())->method('getResponse')->will($this->returnValue($response));
     $response->headers = $this->getMock('\\Symfony\\Component\\HttpFoundation\\ResponseHeaderBag');
     $response->headers->expects($last_modified && !$max_age ? $this->once() : $this->never())->method('addCacheControlDirective')->with('must-revalidate', true);
     $this->listener->onKernelResponse($event);
 }