/**
  * @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/');
 }
 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)));
 }
 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));
 }
 /**
  * @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);
 }
 /**
  * @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);
 }
 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);
 }