本文整理汇总了PHP中Zend\Http\Client\Adapter\Test::addResponse方法的典型用法代码示例。如果您正苦于以下问题:PHP Test::addResponse方法的具体用法?PHP Test::addResponse怎么用?PHP Test::addResponse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Http\Client\Adapter\Test
的用法示例。
在下文中一共展示了Test::addResponse方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testAddResponseAsObject
/**
* Test that responses could be added as objects (ZF-7009)
*
* @link http://framework.zend.com/issues/browse/ZF-7009
* @dataProvider validHttpResponseProvider
*/
public function testAddResponseAsObject($testResponse)
{
$this->adapter->read();
// pop out first response
$respObj = \Zend\Http\Response::fromString($testResponse);
$this->adapter->addResponse($respObj);
$this->assertEquals($testResponse, $this->adapter->read());
}
示例2: testIfClientDoesNotForwardAuthenticationToForeignHost
public function testIfClientDoesNotForwardAuthenticationToForeignHost()
{
// set up user credentials
$user = 'username123';
$password = 'password456';
$encoded = Client::encodeAuthHeader($user, $password, Client::AUTH_BASIC);
$testAdapter = new Test();
$client = new Client(null, array('adapter' => $testAdapter));
// set up two responses that simulate a redirection from example.org to example.com
$testAdapter->setResponse("HTTP/1.1 303 See Other\r\n" . "Location: http://example.com/part2\r\n\r\n" . "The URL of this page has changed.");
$testAdapter->addResponse("HTTP/1.1 200 OK\r\n\r\n" . "Welcome to this Website.");
// set auth and do request
$client->setUri('http://example.org/part1')->setAuth($user, $password, Client::AUTH_BASIC);
$response = $client->setMethod('GET')->send();
// the last request should NOT contain the Authorization header,
// because example.com is different from example.org
$this->assertTrue(strpos($client->getLastRawRequest(), $encoded) === false);
// set up two responses that simulate a rediration from example.org to sub.example.org
$testAdapter->setResponse("HTTP/1.1 303 See Other\r\n" . "Location: http://sub.example.org/part2\r\n\r\n" . "The URL of this page has changed.");
$testAdapter->addResponse("HTTP/1.1 200 OK\r\n\r\n" . "Welcome to this Website.");
// set auth and do request
$client->setUri('http://example.org/part1')->setAuth($user, $password, Client::AUTH_BASIC);
$response = $client->setMethod('GET')->send();
// the last request should contain the Authorization header,
// because sub.example.org is a subdomain unter example.org
$this->assertFalse(strpos($client->getLastRawRequest(), $encoded) === false);
// set up two responses that simulate a rediration from sub.example.org to example.org
$testAdapter->setResponse("HTTP/1.1 303 See Other\r\n" . "Location: http://example.org/part2\r\n\r\n" . "The URL of this page has changed.");
$testAdapter->addResponse("HTTP/1.1 200 OK\r\n\r\n" . "Welcome to this Website.");
// set auth and do request
$client->setUri('http://sub.example.org/part1')->setAuth($user, $password, Client::AUTH_BASIC);
$response = $client->setMethod('GET')->send();
// the last request should NOT contain the Authorization header,
// because example.org is not a subdomain unter sub.example.org
$this->assertTrue(strpos($client->getLastRawRequest(), $encoded) === false);
}