Exemplo n.º 1
0
 public function testWrapsMethods()
 {
     $a = new ArrayCache();
     $a->save('foo', '123');
     $c = new DoctrineCacheAdapter($a);
     $s = new DefaultCacheStorage($c, 100);
     $this->assertEquals('123', $s->fetch('foo'));
     $s->delete('foo');
     $this->assertNotEquals('123', $s->fetch('foo'));
 }
 public function testHandles404RevalidationResponses()
 {
     $request = new Request('GET', 'http://foo.com');
     $request->setClient(new Client());
     $badResponse = new Response(404, array(), 'Oh no!');
     $badRequest = clone $request;
     $badRequest->setResponse($badResponse, true);
     $response = new Response(200, array(), 'foo');
     // Seed the cache
     $s = new DefaultCacheStorage(new DoctrineCacheAdapter(new ArrayCache()));
     $s->cache($request, $response);
     $this->assertNotNull($s->fetch($request));
     $rev = $this->getMockBuilder('Guzzle\\Plugin\\Cache\\DefaultRevalidation')->setConstructorArgs(array($s))->setMethods(array('createRevalidationRequest'))->getMock();
     $rev->expects($this->once())->method('createRevalidationRequest')->will($this->returnValue($badRequest));
     try {
         $rev->revalidate($request, $response);
         $this->fail('Should have thrown an exception');
     } catch (BadResponseException $e) {
         $this->assertSame($badResponse, $e->getResponse());
         $this->assertNull($s->fetch($request));
     }
 }