當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。