本文整理汇总了PHP中Guzzle\Http\Message\Response::setHeaders方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::setHeaders方法的具体用法?PHP Response::setHeaders怎么用?PHP Response::setHeaders使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Guzzle\Http\Message\Response
的用法示例。
在下文中一共展示了Response::setHeaders方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGetAllProjects
/**
* @covers \Wordsmith\Project::all
*/
public function testGetAllProjects()
{
$mockResponse = new Response(200);
$mockResponseBody = EntityBody::factory(fopen(__DIR__ . '/mock/bodies/projects.txt', 'r+'));
$mockResponse->setBody($mockResponseBody);
$mockResponse->setHeaders(array("Host" => "httpbin.org", "User-Agent" => "curl/7.19.7 (universal-apple-darwin10.0) libcurl/7.19.7 OpenSSL/0.9.8l zlib/1.2.3", "Accept" => "application/json", "Content-Type" => "application/json"));
$plugin = new MockPlugin();
$plugin->addResponse($mockResponse);
$client = new HttpClient();
$client->addSubscriber($plugin);
$request = $client->get('https://api.automatedinsights.com/v1/projects');
$response = $request->send();
$this->assertEquals(200, $response->getStatusCode());
$this->assertTrue(in_array('Host', array_keys($response->getHeaders()->toArray())));
$this->assertTrue($response->hasHeader("User-Agent"));
$this->assertCount(4, $response->getHeaders());
$this->assertSame($mockResponseBody->getSize(), $response->getBody()->getSize());
$this->assertSame(1, count(json_decode($response->getBody(true))->data));
}