本文整理汇总了PHP中Guzzle\Http\Client::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::expects方法的具体用法?PHP Client::expects怎么用?PHP Client::expects使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Guzzle\Http\Client
的用法示例。
在下文中一共展示了Client::expects方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testPatch
public function testPatch()
{
$statusCode = 200;
$url = '/translation/';
$headers = array('Authorization' => 'ApiKey none:none');
$post_data = json_encode(array('objects' => array(0 => array('text' => 'Some kind of text', 'target_language' => 'ru'), 1 => array('text' => 'Some kind of other text', 'target_language' => 'latin'))));
$response_json = '{"objects": [{"uid": "vvvvvv"}, {"uid": "eeeeee"}]}';
$this->client->expects($this->once())->method('patch')->with($url, $headers, $post_data, array())->willReturn(new MockRequest($statusCode, $headers, $response_json));
$response = $this->httpDriver->patch($url, $headers, $post_data);
$this->assertEquals(json_decode($response_json, true), $response->json());
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals($response_json, $response->raw());
}
示例2: shouldRegisterSubscribers
/**
* @test
*/
public function shouldRegisterSubscribers()
{
$this->setUp();
$this->guzzleMock->expects($this->once())->method('addSubscriber');
$event = $this->getMock('Symfony\\Component\\EventDispatcher\\EventSubscriberInterface');
$this->testApi->addSubscriber($event);
}
示例3: buildDialogue
/**
* @param string $path
* @param bool $is_error
* @param mixed $data
*/
protected function buildDialogue($path, $is_error, $data = null)
{
/* @var $request \PHPUnit_Framework_MockObject_MockObject|RequestInterface */
$request = $this->getMock('\\Guzzle\\Http\\Message\\RequestInterface');
/* @var $response \PHPUnit_Framework_MockObject_MockObject|Response */
$response = $this->getMockBuilder('\\Guzzle\\Http\\Message\\Response')->disableOriginalConstructor()->getMock();
$this->client->expects($this->once())->method('get')->with($this->api_prefix . $path)->will($this->returnValue($request));
$request->expects($this->once())->method('send')->will($this->returnValue($response));
$response->expects($this->once())->method('isError')->will($this->returnValue($is_error));
if (!$is_error) {
$response->expects($this->once())->method('getBody')->with(true)->will($this->returnValue($data ? json_encode($data) : $data));
}
}
示例4: buildDialogue
/**
* @param string $request
* @param array $params
* @param string $data
*/
protected function buildDialogue($request, array $params, $data = '')
{
$this->client->expects($this->once())->method('get')->with($this->getUrl($request, $params))->will($this->returnValue($this->request));
$this->request->expects($this->once())->method('setHeader')->with('User-Agent', $this->app_code)->will($this->returnValue($this->request));
$this->request->expects($this->once())->method('send')->will($this->returnValue($this->response));
$this->response->expects($this->once())->method('isError')->will($this->returnValue(!$data));
if ($data) {
$this->response->expects($this->once())->method('getBody')->with(true)->will($this->returnValue(gzencode($data)));
$this->response_repair->expects($this->once())->method('repair')->with($data)->will($this->returnValue($data));
} else {
$this->response->expects($this->never())->method('getBody');
$this->response_repair->expects($this->never())->method('repair');
}
}
示例5: dialog
/**
* @param bool $is_successful
* @param string $url
*/
protected function dialog($is_successful = true, $url = '')
{
$this->response->expects($this->once())->method('isSuccessful')->will($this->returnValue($is_successful));
$this->request->expects($this->once())->method('send')->will($this->returnValue($this->response));
$this->client->expects($this->once())->method('get')->with($url ?: $this->url)->will($this->returnValue($this->request));
}
示例6: getShouldConfigureHeaders
/**
* @test
*/
public function getShouldConfigureHeaders()
{
$client = new Client($this->httpClient);
$this->httpClient->expects($this->once())->method('get')->with('/test?name=Test', null, ['verify' => false])->willReturn($this->request);
$this->assertInstanceOf('SimpleXMLElement', $client->get('/test?name=Test'));
}