コード例 #1
0
 /**
  * @dataProvider cacheRevalidationDataProvider
  */
 public function testRevalidatesResponsesAgainstOriginServer($can, $request, $response, $validate = null, $result = null)
 {
     // Send some responses to the test server for cache validation
     $server = $this->getServer();
     $server->flush();
     if ($validate) {
         $server->enqueue($validate);
     }
     $request = RequestFactory::getInstance()->fromMessage("GET / HTTP/1.1\r\nHost: 127.0.0.1:" . $server->getPort() . "\r\n" . $request);
     $response = Response::fromMessage($response);
     $request->setClient(new Client());
     $plugin = new CachePlugin(new DoctrineCacheAdapter(new ArrayCache()));
     $this->assertEquals($can, $plugin->canResponseSatisfyRequest($request, $response), '-> ' . $request . "\n" . $response);
     if ($result) {
         $result = Response::fromMessage($result);
         $result->removeHeader('Date');
         $request->getResponse()->removeHeader('Date');
         $request->getResponse()->removeHeader('Connection');
         // Get rid of dates
         $this->assertEquals((string) $result, (string) $request->getResponse());
     }
     if ($validate) {
         $this->assertEquals(1, count($server->getReceivedRequests()));
     }
 }
コード例 #2
0
 /**
  * @dataProvider satisfyProvider
  */
 public function testChecksIfResponseCanSatisfyRequest($request, $response, $can, $revalidates)
 {
     $didRevalidate = false;
     $revalidate = $this->getMockBuilder('Guzzle\\Plugin\\Cache\\RevalidationInterface')->setMethods(array('revalidate'))->getMockForAbstractClass();
     $revalidate->expects($this->any())->method('revalidate')->will($this->returnCallback(function () use(&$didRevalidate) {
         $didRevalidate = true;
         return true;
     }));
     $plugin = new CachePlugin(array('storage' => $this->getMockBuilder('Guzzle\\Plugin\\Cache\\CacheStorageInterface')->getMockForAbstractClass(), 'revalidation' => $revalidate));
     $this->assertEquals($can, $plugin->canResponseSatisfyRequest($request, $response));
     $this->assertEquals($didRevalidate, $revalidates);
 }