function it_fetches_data_from_next_page(Facebook $fb, FacebookResponse $firstPageResponse, FacebookResponse $secondPageResponse)
 {
     $firstPageResponse->getDecodedBody()->willReturn(['data' => [['name' => 'John Doe'], ['name' => 'Peter Falk'], ['name' => 'James Bond']], 'paging' => ['next' => 'nextPageUrl', 'cursors' => ['after' => 'nextPageId']]]);
     $fb->get('/eventId/attending', self::ACCESS_TOKEN)->willReturn($firstPageResponse);
     $secondPageResponse->getDecodedBody()->willReturn(['data' => [['name' => 'Bruce Lee'], ['name' => 'Sean Connery']]]);
     $fb->get('/eventId/attending?after=nextPageId', self::ACCESS_TOKEN)->willReturn($secondPageResponse);
     $this->get('eventId', self::ACCESS_TOKEN)->shouldReturn(['Bond James', 'Connery Sean', 'Doe John', 'Falk Peter', 'Lee Bruce']);
 }
 public function testASuccessfulUrlEncodedKeyValuePairResponseWillBeDecoded()
 {
     $graphResponseKeyValuePairs = 'id=123&name=Foo';
     $response = new FacebookResponse($this->request, $graphResponseKeyValuePairs, 200);
     $decodedResponse = $response->getDecodedBody();
     $this->assertFalse($response->isError(), 'Did not expect Response to return an error.');
     $this->assertEquals(['id' => '123', 'name' => 'Foo'], $decodedResponse);
 }
 /**
  * Creates a new Response entity.
  *
  * @param FacebookBatchRequest $batchRequest
  * @param FacebookResponse     $response
  */
 public function __construct(FacebookBatchRequest $batchRequest, FacebookResponse $response)
 {
     $this->batchRequest = $batchRequest;
     $request = $response->getRequest();
     $body = $response->getBody();
     $httpStatusCode = $response->getHttpStatusCode();
     $headers = $response->getHeaders();
     parent::__construct($request, $body, $httpStatusCode, $headers);
     $responses = $response->getDecodedBody();
     $this->setResponses($responses);
 }
 /**
  * A factory for creating the appropriate exception based on the response from Graph.
  *
  * @param FacebookResponse $response The response that threw the exception.
  *
  * @return FacebookResponseException
  */
 public static function create(FacebookResponse $response)
 {
     $data = $response->getDecodedBody();
     if (!isset($data['error']['code']) && isset($data['code'])) {
         $data = ['error' => $data];
     }
     $code = isset($data['error']['code']) ? $data['error']['code'] : null;
     $message = isset($data['error']['message']) ? $data['error']['message'] : 'Unknown error from Graph.';
     $previousException = null;
     if (isset($data['error']['error_subcode'])) {
         switch ($data['error']['error_subcode']) {
             // Other authentication issues
             case 458:
             case 459:
             case 460:
             case 463:
             case 464:
             case 467:
                 return new static($response, new FacebookAuthenticationException($message, $code));
         }
     }
     switch ($code) {
         // Login status or token expired, revoked, or invalid
         case 100:
         case 102:
         case 190:
             return new static($response, new FacebookAuthenticationException($message, $code));
             // Server issue, possible downtime
         // Server issue, possible downtime
         case 1:
         case 2:
             return new static($response, new FacebookServerException($message, $code));
             // API Throttling
         // API Throttling
         case 4:
         case 17:
         case 341:
             return new static($response, new FacebookThrottleException($message, $code));
             // Duplicate Post
         // Duplicate Post
         case 506:
             return new static($response, new FacebookClientException($message, $code));
     }
     // Missing Permissions
     if ($code == 10 || $code >= 200 && $code <= 299) {
         return new static($response, new FacebookAuthorizationException($message, $code));
     }
     // OAuth authentication error
     if (isset($data['error']['type']) && $data['error']['type'] === 'OAuthException') {
         return new static($response, new FacebookAuthenticationException($message, $code));
     }
     // All others
     return new static($response, new FacebookOtherException($message, $code));
 }
 /**
  * Init this Graph object.
  *
  * @param FacebookResponse $response The response entity from Graph.
  */
 public function __construct(FacebookResponse $response)
 {
     $this->response = $response;
     $this->decodedBody = $response->getDecodedBody();
 }