本文整理汇总了PHP中Guzzle\Http\Message\Request::setResponse方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::setResponse方法的具体用法?PHP Request::setResponse怎么用?PHP Request::setResponse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Guzzle\Http\Message\Request
的用法示例。
在下文中一共展示了Request::setResponse方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSetManualResponse
/**
* @covers Guzzle\Http\Message\Request::setResponse
* @covers Guzzle\Http\Message\Request::getResponse
* @covers Guzzle\Http\Message\Request::getState
*/
public function testSetManualResponse()
{
$response = new Response(200, array('Date' => 'Sat, 16 Oct 2010 17:27:14 GMT', 'Expires' => '-1', 'Cache-Control' => 'private, max-age=0', 'Content-Type' => 'text/html; charset=ISO-8859-1'), 'response body');
$this->assertSame($this->request, $this->request->setResponse($response), '-> setResponse() must use a fluent interface');
$this->assertEquals('complete', $this->request->getState(), '-> setResponse() must change the state of the request to complete');
$this->assertSame($response, $this->request->getResponse(), '-> setResponse() must set the exact same response that was passed in to it');
}
示例2: 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());
}