本文整理汇总了PHP中Guzzle\Http\Message\Request::setClient方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::setClient方法的具体用法?PHP Request::setClient怎么用?PHP Request::setClient使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Guzzle\Http\Message\Request
的用法示例。
在下文中一共展示了Request::setClient方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
public function setUp()
{
$this->client = $this->getSimpleMock('Guzzle\\Http\\ClientInterface');
$this->facade = new RequestCollectionFacade($this->client);
$this->request = new Request('GET', '/_request/last');
$this->request->setClient($this->client);
}
示例2: testHandles404RevalidationResponses
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');
$plugin = new CachePlugin();
$c = new ArrayCache();
$c->save('foo', array(200, array(), 'foo'));
$s = new DefaultCacheStorage(new DoctrineCacheAdapter($c));
$k = new CallbackCacheKeyProvider(function () {
return 'foo';
});
$rev = $this->getMockBuilder('Guzzle\\Plugin\\Cache\\DefaultRevalidation')->setConstructorArgs(array($k, $s, $plugin))->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->assertFalse($c->fetch('foo'));
}
}
示例3: testCreatesPreSignedUrlWithXAmzHeaders
public function testCreatesPreSignedUrlWithXAmzHeaders()
{
$signature = new S3Signature();
$request = new Request('GET', 'https://s3.amazonaws.com', array('X-Amz-Acl' => 'public-read'));
$c = $this->getServiceBuilder()->get('s3');
$request->setClient($c);
$this->assertContains('x-amz-acl:public-read', $signature->createCanonicalizedString($request, time()));
$this->assertContains('&x-amz-acl=public-read', $signature->createPresignedUrl($request, $c->getCredentials(), time()));
}
示例4: testAddsCookiesToRequests
/**
* @covers Guzzle\Http\Plugin\CookiePlugin
*/
public function testAddsCookiesToRequests()
{
ArrayCookieJarTest::addCookies($this->storage);
$this->storage->save(array('domain' => '.y.example.com', 'path' => '/acme/', 'cookie' => array('secure', 'sec'), 'expires' => Guzzle::getHttpDate('+1 day'), 'secure' => true));
// Add a cookie that is only set on a specific port, so it wont be
// added to the following requests
$this->storage->save(array('domain' => '.y.example.com', 'path' => '/acme/', 'cookie' => array('test', 'port'), 'expires' => Guzzle::getHttpDate('+1 day'), 'secure' => false, 'port' => array(8192)));
$request1 = new Request('GET', 'https://a.y.example.com/acme/');
$request1->setClient(new Client());
$request2 = new Request('GET', 'https://a.y.example.com/acme/');
$request2->setClient(new Client());
$request3 = new Request('GET', 'http://a.y.example.com/acme/');
$request3->setClient(new Client());
$request4 = new Request('GET', 'http://a.y.example.com/acme/');
$request4->setClient(new Client());
$request1->getEventDispatcher()->addSubscriber($this->plugin);
$request2->getEventDispatcher()->addSubscriber($this->plugin);
$request3->getEventDispatcher()->addSubscriber($this->plugin);
$request4->getEventDispatcher()->addSubscriber($this->plugin);
// Set a secure cookie
$response1 = Response::fromMessage("HTTP/1.1 200 OK\r\nSet-Cookie: a=b; c=d; Max-Age=86400; domain=.example.com; secure;\r\n\r\n");
// Set a regular cookie
$response2 = Response::fromMessage("HTTP/1.1 200 OK\r\nSet-Cookie: e=f h; discard; domain=.example.com;\r\n\r\n");
$response3 = Response::fromMessage("HTTP/1.1 200 OK\r\n\r\n");
$request1->setResponse($response1, true);
$request2->setResponse($response2, true);
$request3->setResponse($response3, true);
$request1->send();
$request2->send();
$request3->send();
$this->assertEquals('muppet=cookie_monster;secure=sec', (string) $request1->getCookie());
$this->assertEquals('muppet=cookie_monster;secure=sec;a=b;c=d', (string) $request2->getCookie());
$this->assertEquals('muppet=cookie_monster;e=f h', (string) $request3->getCookie());
// Clear the e=f h temporary cookie
$this->plugin->clearTemporaryCookies();
$request4->setResponse($response3, true);
$request4->send();
$this->assertEquals('muppet=cookie_monster', (string) $request4->getCookie());
}
示例5: testRequestThrowsExceptionOnBadResponse
/**
* @covers Guzzle\Http\Message\Request::getResponse
* @covers Guzzle\Http\Message\Request::processResponse
* @covers Guzzle\Http\Message\Request::getResponseBody
*/
public function testRequestThrowsExceptionOnBadResponse()
{
$response = new Response(404, array('Content-Length' => 3), 'abc');
$request = new Request('GET', 'http://www.google.com/');
$request->setClient($this->client);
try {
$request->setResponse($response, true);
$request->send();
$this->fail('Expected exception not thrown');
} catch (BadResponseException $e) {
$this->assertInstanceOf('Guzzle\\Http\\Message\\RequestInterface', $e->getRequest());
$this->assertInstanceOf('Guzzle\\Http\\Message\\Response', $e->getResponse());
$this->assertContains('Client error response', $e->getMessage());
}
}
示例6: testRequestsManageClients
/**
* @covers Guzzle\Http\Message\Request::getClient
* @covers Guzzle\Http\Message\Request::setClient
*/
public function testRequestsManageClients()
{
$request = new Request('GET', 'http://test.com');
$this->assertNull($request->getClient());
$request->setClient($this->client);
$this->assertSame($this->client, $request->getClient());
}