當前位置: 首頁>>代碼示例>>PHP>>正文


PHP HttpSocket::expectCallCount方法代碼示例

本文整理匯總了PHP中HttpSocket::expectCallCount方法的典型用法代碼示例。如果您正苦於以下問題:PHP HttpSocket::expectCallCount方法的具體用法?PHP HttpSocket::expectCallCount怎麽用?PHP HttpSocket::expectCallCount使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在HttpSocket的用法示例。


在下文中一共展示了HttpSocket::expectCallCount方法的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);
        }
    }
開發者ID:CakeDC,項目名稱:bitly,代碼行數:58,代碼來源:BitlyApiBehaviorTest.php


注:本文中的HttpSocket::expectCallCount方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。