本文整理汇总了PHP中GuzzleHttp\Client::shouldReceive方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::shouldReceive方法的具体用法?PHP Client::shouldReceive怎么用?PHP Client::shouldReceive使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GuzzleHttp\Client
的用法示例。
在下文中一共展示了Client::shouldReceive方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testThrowsExceptionOnClientError
/**
* @expectedException \Facebook\Exceptions\FacebookSDKException
*/
public function testThrowsExceptionOnClientError()
{
$requestMock = m::mock('GuzzleHttp\\Message\\RequestInterface');
$exceptionMock = m::mock('GuzzleHttp\\Exception\\RequestException', ['Foo Error', $requestMock, null, m::mock('GuzzleHttp\\Exception\\AdapterException')]);
$this->guzzleMock->shouldReceive('createRequest')->once()->with('GET', 'http://foo.com/', [])->andReturn($requestMock);
$this->guzzleMock->shouldReceive('send')->once()->with($requestMock)->andThrow($exceptionMock);
$this->guzzleClient->send('http://foo.com/');
}
示例2: guzzleClientShouldSetupToken
private function guzzleClientShouldSetupToken()
{
$this->guzzleClient->shouldReceive('post')->with(WhenIWorkApi::WHEN_I_WORK_ENDPOINT . '/login', array('headers' => array('W-Key' => self::DEVELOPER_KEY), 'json' => array('username' => self::USERNAME, 'password' => self::PASSWORD)))->once()->andReturn($this->request);
$mockStream = \Mockery::mock('GuzzleHttp\\Psr7\\Stream');
$mockStream->shouldReceive('close')->once();
$mockStream->shouldReceive('getContents')->once()->andReturn('{"login":{"token":"someHiddenToken"}}');
$this->request->shouldReceive('getBody')->once()->andReturn($mockStream);
$this->request->shouldReceive('\\GuzzleHttp\\json_decode')->andReturn(array('login' => array('token' => self::TOKEN)));
}
示例3: testRetrievesTemperatureFromApiIfNotFoundInCache
public function testRetrievesTemperatureFromApiIfNotFoundInCache()
{
$city = 'Miami, FL';
$expectedTemperature = '90F';
$expectedCacheKey = md5($city);
$temperatureData = ['temperature' => $expectedTemperature];
$this->cache->shouldReceive('get')->once()->with($expectedCacheKey)->andReturn(null);
$this->cache->shouldReceive('set')->once()->with($expectedCacheKey, $temperatureData, 900);
$this->httpClient->shouldReceive('get')->once()->with('https://some-weather-api.com/temperature/' . urlencode($city))->andReturn(new Response(200, [], Stream::factory(json_encode($temperatureData))));
$this->assertSame($expectedTemperature, $this->weatherService->getTemperature($city));
}
示例4: testClientCalls
/**
* @dataProvider clientCallDataProvider
* @param $namespace
* @param $method
* @param $expectedUri
*/
public function testClientCalls($namespace, $method, $expectedUri)
{
$client = $this->createClient();
$response = m::mock('GuzzleHttp\\Message\\ResponseInterface');
$response->shouldReceive('getBody')->andReturn(TestFixtures::getFixture('accounts.getAccountInfo'));
$this->guzzleClient->shouldReceive('get')->with($expectedUri, ['query' => ['apiKey' => 'key', 'secret' => 'secret', 'params' => 'passedThrough'], 'cert' => $this->certPath])->andReturn($response);
$gigyaResponse = m::mock('Graze\\Gigya\\Response\\ResponseInterface');
$this->factory->shouldReceive('getResponse')->with($response)->andReturn($gigyaResponse);
$result = $client->{$namespace}()->{$method}(['params' => 'passedThrough']);
static::assertSame($gigyaResponse, $result);
}
示例5: testThrowsExceptionOnClientError
/**
* @expectedException \Facebook\Exceptions\FacebookSDKException
*/
public function testThrowsExceptionOnClientError()
{
$request = new Request('GET', 'http://foo.com');
$this->guzzleMock->shouldReceive('createRequest')->once()->with('GET', 'http://foo.com/', m::on(function ($arg) {
// array_diff_assoc() will sometimes trigger error on child-arrays
if ([] !== $arg['headers']) {
return false;
}
unset($arg['headers']);
$caInfo = array_diff_assoc($arg, ['body' => 'foo_body', 'timeout' => 60, 'connect_timeout' => 10]);
if (count($caInfo) !== 1) {
return false;
}
if (1 !== preg_match('/.+\\/certs\\/DigiCertHighAssuranceEVRootCA\\.pem$/', $caInfo['verify'])) {
return false;
}
return true;
}))->andReturn($request);
$this->guzzleMock->shouldReceive('send')->once()->with($request)->andThrow(new RequestException('Foo', $request));
$this->guzzleClient->send('http://foo.com/', 'GET', 'foo_body', [], 60);
}
示例6: remoteAppDoesNotRespond
private function remoteAppDoesNotRespond()
{
$this->response->shouldReceive('getBody')->andReturn($this->faker->word);
$this->badResponseException->shouldReceive('getResponse')->andReturn($this->response);
$this->client->shouldReceive('request')->andThrow($this->badResponseException);
}