public function debug() { $r = new Response(); var_dump($r->getReasonPhrase()); $req = new Request(); $req->getParams(); $req->getPath(); }
public function testFiltersCacheKey() { $request = new Request('GET', 'http://foo.com?a=b&c=d', array('Abc' => '123', 'Def' => '456')); $request->getParams()->set(DefaultCacheKeyProvider::CACHE_KEY_FILTER, 'header=Def; query=c'); $provider = new DefaultCacheKeyProvider(); $provider->getCacheKey($request); $this->assertNotEmpty($request->getParams()->get(DefaultCacheKeyProvider::CACHE_KEY)); $cloned = clone $request; $cloned->getQuery()->remove('c'); $cloned->removeHeader('Def'); $this->assertEquals((string) $cloned, $request->getParams()->get(DefaultCacheKeyProvider::CACHE_KEY_RAW)); }
/** * @covers Guzzle\Http\Message\Request::__clone */ public function testClonedRequestsUseNewInternalState() { $p = new AsyncPlugin(); $this->request->getEventDispatcher()->addSubscriber($p); $h = $this->request->getHeader('Host'); $r = clone $this->request; $this->assertEquals(RequestInterface::STATE_NEW, $r->getState()); $this->assertNotSame($r->getQuery(), $this->request->getQuery()); $this->assertNotSame($r->getCurlOptions(), $this->request->getCurlOptions()); $this->assertNotSame($r->getEventDispatcher(), $this->request->getEventDispatcher()); $this->assertEquals($r->getHeaders(), $this->request->getHeaders()); $this->assertNotSame($h, $r->getHeader('Host')); $this->assertNotSame($r->getParams(), $this->request->getParams()); $this->assertTrue($this->request->getEventDispatcher()->hasListeners('request.sent')); }
/** * @covers Guzzle\Http\Message\AbstractMessage::getParams */ public function testGetParams() { $request = new Request('GET', 'http://example.com'); $this->assertInstanceOf('Guzzle\\Common\\Collection', $request->getParams()); }
/** * @dataProvider satisfiableOnErrorProvider */ public function testInjectsSatisfiableResponsesOnException($cacheResponse) { $storage = $this->getMockBuilder('Guzzle\\Plugin\\Cache\\CacheStorageInterface')->setMethods(array('fetch'))->getMockForAbstractClass(); $storage->expects($this->exactly(2))->method('fetch')->will($this->returnValue($cacheResponse)); $plugin = new CachePlugin(array('storage' => $storage)); $request = new Request('GET', 'http://foo.com', array('Cache-Control' => 'max-stale')); $plugin->onRequestBeforeSend(new Event(array('request' => $request))); $plugin->onRequestException(new Event(array('request' => $request, 'response' => $request->getResponse(), 'exception' => $this->getMock('Guzzle\\Http\\Exception\\CurlException')))); $plugin->onRequestSent(new Event(array('request' => $request, 'response' => $response = $request->getResponse()))); $this->assertEquals($cacheResponse->getStatusCode(), $response->getStatusCode()); $this->assertEquals((string) $cacheResponse->getBody(), (string) $response->getBody()); $this->assertTrue($response->hasHeader('Age')); if ($response->isFresh() === false) { $this->assertContains('110', (string) $response->getHeader('Warning')); } $this->assertSame(sprintf('%s GuzzleCache/%s', $request->getProtocolVersion(), Version::VERSION), (string) $request->getHeader('Via')); $this->assertSame(sprintf('%s GuzzleCache/%s', $request->getProtocolVersion(), Version::VERSION), (string) $response->getHeader('Via')); $this->assertTrue($request->getParams()->get('cache.lookup')); $this->assertSame('error', $request->getParams()->get('cache.hit')); $this->assertTrue($response->hasHeader('X-Cache-Lookup')); $this->assertTrue($response->hasHeader('X-Cache')); $this->assertEquals('HIT from GuzzleCache', (string) $response->getHeader('X-Cache-Lookup')); $this->assertEquals('HIT_ERROR from GuzzleCache', (string) $response->getHeader('X-Cache')); }
public function testPurgesRequestsWithCustomMethods() { $storage = $this->getMockBuilder('Guzzle\\Plugin\\Cache\\CacheStorageInterface')->setMethods(array('delete'))->getMockForAbstractClass(); $storage->expects($this->exactly(2))->method('delete'); $plugin = new CachePlugin(array('storage' => $storage)); $request = new Request('GET', 'http://foo.com', array('X-Foo' => 'Bar')); $request->getParams()->set('cache.purge_methods', array('FOO', 'BAR')); $plugin->purge($request); }