当前位置: 首页>>代码示例>>PHP>>正文


PHP Client::shouldReceive方法代码示例

本文整理汇总了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/');
 }
开发者ID:BASSINOT,项目名称:facebook-php-sdk-v4,代码行数:11,代码来源:FacebookGuzzleHttpClientTest.php

示例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)));
 }
开发者ID:mybuilder,项目名称:when-i-work-api,代码行数:9,代码来源:WhenIWorkApiTest.php

示例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));
 }
开发者ID:michaelmoussa,项目名称:talks,代码行数:11,代码来源:WeatherServiceTest.php

示例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);
 }
开发者ID:adragus-inviqa,项目名称:gigya-client,代码行数:17,代码来源:GigyaTest.php

示例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);
 }
开发者ID:barabash97,项目名称:coolpost,代码行数:24,代码来源:FacebookGuzzleHttpClientTest.php

示例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);
 }
开发者ID:remi-san,项目名称:word-selector,代码行数:6,代码来源:WordSelectorProxyAdapterTest.php


注:本文中的GuzzleHttp\Client::shouldReceive方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。