本文整理汇总了PHP中HttpSocket::expectAt方法的典型用法代码示例。如果您正苦于以下问题:PHP HttpSocket::expectAt方法的具体用法?PHP HttpSocket::expectAt怎么用?PHP HttpSocket::expectAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpSocket
的用法示例。
在下文中一共展示了HttpSocket::expectAt方法的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);
}
}