本文整理匯總了PHP中HttpSocket::setReturnValueAt方法的典型用法代碼示例。如果您正苦於以下問題:PHP HttpSocket::setReturnValueAt方法的具體用法?PHP HttpSocket::setReturnValueAt怎麽用?PHP HttpSocket::setReturnValueAt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類HttpSocket
的用法示例。
在下文中一共展示了HttpSocket::setReturnValueAt方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testStats
/**
* Test stats API call
*
* @return void
*/
public function testStats()
{
$getCallCount = 0;
$this->Http->response['status']['code'] = 200;
// Test normal call
$params['hash'] = 'R8hVH';
// cakephp.org
$expectedParams = array('http://api.bit.ly/stats', array('hash' => 'R8hVH', 'format' => 'json', 'login' => 'testLogin', 'apiKey' => 'testApiKey', 'version' => '2.0.1'));
ksort($expectedParams[1]);
$responseData = array('clicks' => 6, 'hash' => 'R8hVH', 'referrers' => array('' => array('direct' => 4), 'twitter.com' => array('/' => 1, '/home' => 1)));
$response = json_encode(array('errorCode' => 0, 'errorMessage' => '', 'results' => $responseData, 'statusCode' => 'OK'));
$this->Http->expectAt($getCallCount, 'get', $expectedParams);
$this->Http->setReturnValueAt($getCallCount++, 'get', $response);
$result = $this->Model->stats(compact('params'));
$expected = array('result' => $responseData, 'code' => 200);
$this->assertEqual($result, $expected);
// Test XML call
$expectedParams[1]['format'] = 'xml';
$response = '<bitly>
<errorCode>0</errorCode>
<errorMessage></errorMessage>
<results>
<referrers>
<nodeKeyVal>
<direct>4</direct>
<nodeKey><![CDATA[]]></nodeKey>
</nodeKeyVal>
<nodeKeyVal>
<nodeKey><![CDATA[twitter.com]]></nodeKey>
<nodeKeyVal>
<nodeValue><![CDATA[1]]></nodeValue>
<nodeKey><![CDATA[/]]></nodeKey>
</nodeKeyVal>
<nodeKeyVal>
<nodeValue><![CDATA[1]]></nodeValue>
<nodeKey><![CDATA[/home]]></nodeKey>
</nodeKeyVal>
</nodeKeyVal>
</referrers>
<hash>R8hVH</hash>
<clicks>6</clicks>
</results>
<statusCode>OK</statusCode>
</bitly>';
$this->Http->expectAt($getCallCount, 'get', $expectedParams);
$this->Http->setReturnValueAt($getCallCount++, 'get', $response);
$result = $this->Model->stats(array('format' => 'xml', 'params' => $params));
$expected = array('result' => $responseData, 'code' => 200);
$this->assertEqual($result, $expected);
if ($this->__useTestSocket) {
$this->Http->expectCallCount('get', $getCallCount);
}
}