protected function getCacheinfo(GuzzleRequest $request) { $lookup = $request->getConfig()->hasKey('cache_lookup') ? $request->getConfig()->get('cache_lookup') : null; $hit = $request->getConfig()->hasKey('cache_hit') ? $request->getConfig()->get('cache_hit') : null; $key = $request->getConfig()->hasKey('cache.key') ? $request->getConfig()->get('cache.key') : null; $cacheStatus = 'not cached'; if ($hit === true) { $cacheStatus = 'cached'; } elseif (!empty($key) && $lookup == 'MISS') { $cacheStatus = 'cache saved'; } return array('enabled' => $request->getConfig()->hasKey('cache.disable') ? (bool) (!$request->getConfig()->get('cache.disable')) : false, 'ttl' => $request->getConfig()->hasKey('cache.ttl') ? (int) $request->getConfig()->get('cache.ttl') : null, 'key' => $key, 'status' => $cacheStatus); }
public function testCloneIsDeep() { $r = new Request('GET', '/test', ['foo' => 'baz'], Stream::factory('foo')); $r2 = clone $r; $this->assertNotSame($r->getEmitter(), $r2->getEmitter()); $this->assertEquals('foo', $r2->getBody()); $r->getConfig()->set('test', 123); $this->assertFalse($r2->getConfig()->hasKey('test')); $r->setPath('/abc'); $this->assertEquals('/test', $r2->getPath()); }
public function testSendsWithStreamingAdapter() { $response = new Response(200); $mock = $this->getMockBuilder('GuzzleHttp\\Adapter\\AdapterInterface')->setMethods(['send'])->getMockForAbstractClass(); $mock->expects($this->never())->method('send'); $streaming = $this->getMockBuilder('GuzzleHttp\\Adapter\\AdapterInterface')->setMethods(['send'])->getMockForAbstractClass(); $streaming->expects($this->once())->method('send')->will($this->returnValue($response)); $request = new Request('GET', '/'); $request->getConfig()->set('stream', true); $s = new StreamingProxyAdapter($mock, $streaming); $this->assertSame($response, $s->send(new Transaction(new Client(), $request))); }
public function testCreatesRingRequests() { $stream = Stream::factory('test'); $request = new Request('GET', 'http://httpbin.org/get?a=b', ['test' => 'hello'], $stream); $request->getConfig()->set('foo', 'bar'); $trans = new Transaction(new Client(), $request); $factory = new MessageFactory(); $fsm = new RequestFsm(function () { }, new MessageFactory()); $r = RingBridge::prepareRingRequest($trans, $factory, $fsm); $this->assertEquals('http', $r['scheme']); $this->assertEquals('1.1', $r['version']); $this->assertEquals('GET', $r['http_method']); $this->assertEquals('http://httpbin.org/get?a=b', $r['url']); $this->assertEquals('/get', $r['uri']); $this->assertEquals('a=b', $r['query_string']); $this->assertEquals(['Host' => ['httpbin.org'], 'test' => ['hello']], $r['headers']); $this->assertSame($stream, $r['body']); $this->assertEquals(['foo' => 'bar'], $r['client']); $this->assertFalse($r['future']); }
/** * @expectedException \GuzzleHttp\Exception\AdapterException */ public function testThrowsForStreamOption() { $request = new Request('GET', Server::$url . 'haha'); $request->getConfig()->set('stream', true); $t = new Transaction(new Client(), $request); $f = new CurlFactory(); $f($t, new MessageFactory()); }
public function testConvertsConstantNameKeysToValues() { $request = new Request('GET', Server::$url); $request->getConfig()->set('curl', ['CURLOPT_USERAGENT' => 'foo']); $this->emit($request); $f = new CurlFactory(); curl_close($f(new Transaction(new Client(), $request), new MessageFactory())); $this->assertEquals('foo', $_SERVER['last_curl'][CURLOPT_USERAGENT]); }