当前位置: 首页>>代码示例>>PHP>>正文


PHP Request::setClient方法代码示例

本文整理汇总了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);
 }
开发者ID:cosmorogers,项目名称:http-mock,代码行数:7,代码来源:RequestCollectionFacadeTest.php

示例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'));
     }
 }
开发者ID:KANU82,项目名称:guzzle,代码行数:25,代码来源:DefaultRevalidationTest.php

示例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()));
 }
开发者ID:myrichhub,项目名称:mssapi_php,代码行数:9,代码来源:S3SignatureTest.php

示例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());
 }
开发者ID:MicroSDHC,项目名称:justinribeiro.com-examples,代码行数:42,代码来源:CookiePluginTest.php

示例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());
     }
 }
开发者ID:idiscussforum,项目名称:providence,代码行数:20,代码来源:RequestTest.php

示例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());
 }
开发者ID:biribogos,项目名称:wikihow-src,代码行数:11,代码来源:RequestTest.php


注:本文中的Guzzle\Http\Message\Request::setClient方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。