/**
  * @test
  */
 public function willInvalidateAllParentPaths()
 {
     $this->invokeListener('PUT');
     $this->assertTrue($this->store->containsKey('/foo'));
     $this->assertTrue($this->store->containsKey('/foo/bar'));
     $this->assertTrue($this->store->containsKey('/foo/bar/bah'));
 }
 /**
  * @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;
 }
 /**
  * @test
  */
 public function willCreatePreconditionFailedWhenVersionMismatch()
 {
     $version1 = microtime(true);
     $version2 = $version1 + 1;
     $this->store->update(self::createRequest(), (string) $version1);
     $this->eventMock->expects($this->once())->method('setResponse')->with($this->callback(function (Response $response) {
         return $response->getStatusCode() === Response::HTTP_PRECONDITION_FAILED;
     }));
     $this->invokeListener('POST', ['HTTP_IF_MATCH' => (string) $version2]);
 }
 /**
  * @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")));
 }