protected function setupHttpClient() { $this->httpClient = new Client(); if ($this->getConfig()->graphBaseDomain) { $this->httpClient->setDefaultGraphBaseDomain($this->getConfig()->graphBaseDomain); } if ($this->getConfig()->skipSslVerification) { /** @var CurlAdapter $adapter */ $adapter = $this->httpClient->getAdapter(); $adapter->getOpts()->offsetSet(CURLOPT_SSL_VERIFYHOST, false); $adapter->getOpts()->offsetSet(CURLOPT_SSL_VERIFYPEER, false); } }
public function testSendRequest() { $client = new Client(); // Empty response > json_decode('') = null $client->setAdapter($this->createMockChain(null)); $exception_catched = false; try { $client->sendRequest($this->createRequestMock()); } catch (EmptyResponseException $e) { $exception_catched = true; } $this->assertTrue($exception_catched); // Error payload $client->setAdapter($this->createMockChain(array('error' => array('message' => 'Stub Server Error Message', 'type' => 'FacebookApiException', 'code' => 1)))); $exception_catched = false; try { $client->sendRequest($this->createRequestMock()); } catch (EmptyResponseException $e) { $this->fail("Catched wrong RequestException"); } catch (RequestException $e) { $exception_catched = true; } $this->assertTrue($exception_catched); // Success $client->setAdapter($this->createMockChain(array('id' => 4))); $response = $client->sendRequest($this->createRequestMock()); $this->assertTrue($response instanceof ResponseInterface); $content = $response->getContent(); $this->assertArrayHasKey('id', $content); $this->assertEquals($content['id'], 4); }