/**
  * @test
  */
 public function willLimitAllowedMethods()
 {
     $this->eventMock->expects($this->once())->method('setResponse')->with($this->callback(function (Response $response) {
         return $response->getStatusCode() === Response::HTTP_METHOD_NOT_ALLOWED;
     }));
     $this->invokeListener('FAUX');
     $this->assertEmpty($this->store->fetch(self::createRequest()));
 }
 /**
  * @param Request $request
  *
  * @return null|Response
  */
 private function createResponse(Request $request)
 {
     if (!self::isSupportedMethodRequest($request)) {
         return new Response('', Response::HTTP_METHOD_NOT_ALLOWED);
     }
     if (!($version = $this->store->fetch($request))) {
         return null;
     }
     $method = strtoupper($request->getMethod());
     if ($method === 'GET') {
         $ifNoneMatch = $request->headers->get('If-None-Match');
         if ($ifNoneMatch && $version === $ifNoneMatch) {
             return new Response('', Response::HTTP_NOT_MODIFIED);
         }
     } elseif ($this->concurrencyControl && self::isModifyingMethodRequest($request)) {
         $ifMatch = $request->headers->get('If-Match');
         if (!$ifMatch) {
             return new Response('', Response::HTTP_PRECONDITION_REQUIRED);
         }
         if ($version !== $ifMatch) {
             return new Response('', Response::HTTP_PRECONDITION_FAILED);
         }
     }
     return null;
 }
 /**
  * @param FilterResponseEvent $event
  */
 public function onKernelResponse(FilterResponseEvent $event)
 {
     if (!$event->isMasterRequest()) {
         return;
     }
     $request = $event->getRequest();
     $response = $event->getResponse();
     if (substr((string) $response->getStatusCode(), 0, 1) !== '2') {
         // TODO UT this
         return;
     }
     if (RequestListener::isModifyingMethodRequest($request)) {
         $version = $this->store->update($request, (string) microtime(true));
     } elseif (!RequestListener::isIgnoreMethodRequest($request)) {
         if (!($version = $this->store->fetch($request))) {
             $version = $this->store->register($request, (string) microtime(true));
         }
     }
     if (isset($version)) {
         $response->headers->set('ETag', $version);
     }
 }
 /**
  * @test
  */
 public function savingParentInvalidatesParentsAndOnlyChildrenNotMatchingConstraint()
 {
     $childUri = "/a/b/cee/dee/?eff=gee";
     $originalVersion = microtime(true);
     $this->store->setChildInvalidationConstraint('\\/dee$');
     $this->store->update(Request::create($childUri), $originalVersion);
     $parentUri = "/a/b";
     $newVersion = microtime(true);
     $this->store->update(Request::create($parentUri), $newVersion);
     $this->assertSame($newVersion, $this->store->fetch(Request::create("/a")));
     $this->assertSame($newVersion, $this->store->fetch(Request::create("/a/b")));
     $this->assertSame($newVersion, $this->store->fetch(Request::create("/a/b/cee")));
     $this->assertSame($originalVersion, $this->store->fetch(Request::create("/a/b/cee/dee")));
     $this->assertSame($originalVersion, $this->store->fetch(Request::create("/a/b/cee/dee/?eff=gee")));
 }
 /**
  * @test
  */
 public function willSaveVersionOnModifiedRequest()
 {
     $this->invokeListener('PUT');
     $this->assertRegExp('/\\d{10}\\.\\d+/', $this->store->fetch(self::createRequest()));
 }