diff --git a/CHANGELOG.md b/CHANGELOG.md index d820b9618..1c0aabd09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ Starting with version 5, the Facebook PHP SDK follows [SemVer](http://semver.org - Replace custom CSPRNG implementation with `paragonie/random_compat` (#644) - Removed the built-in autoloader in favor of composer's autoloader (#646) - Big integers in signed requests get decoded as `string` instead of `float` (#699) + - We use an HTTP client abstraction called HTTPlug to give the user more control over *how* to send PSR7 messages. See updated installation instructions. + - Removed option `http_client_handler` + - Added option `http_client` which should be an object implementing `\Http\Client\HttpClient` + - Removed functions `FacebookClient::setHttpClientHandler()` and `FacebookClient::getHttpClientHandler()` in favor for `FacebookClient::getHttpClient()` and `FacebookClient::setHttpClient()`. ## 5.x diff --git a/README.md b/README.md index c285a7b26..234438ed2 100644 --- a/README.md +++ b/README.md @@ -15,9 +15,11 @@ This repository contains the open source PHP SDK that allows you to access the F The Facebook PHP SDK can be installed with [Composer](https://getcomposer.org/). Run this command: ```sh -composer require facebook/graph-sdk +composer require facebook/graph-sdk php-http/curl-client guzzlehttp/psr7 ``` +Why the extra packages? We give you the flexibility to choose what HTTP client (e.g. cURL or Guzzle) to use and what PSR-7 implementation you prefer. Read more about this at the [HTTPlug documentation](http://php-http.readthedocs.io/en/latest/httplug/users.html). + ## Usage diff --git a/composer.json b/composer.json index 8c3ae8aeb..130a77a59 100644 --- a/composer.json +++ b/composer.json @@ -15,14 +15,17 @@ "sort-packages": true }, "require": { - "php": "^7.1" + "php": "^7.1", + "psr/http-message": "^1.0", + "php-http/client-implementation": "^1.0", + "php-http/httplug": "^1.0", + "php-http/discovery": "^1.0", + + "php-http/message": "^1.0" }, "require-dev": { - "guzzlehttp/guzzle": "^5.3.1", - "phpunit/phpunit": "^6.2" - }, - "suggest": { - "guzzlehttp/guzzle": "Allows for implementation of the Guzzle HTTP client" + "phpunit/phpunit": "^6.2", + "php-http/guzzle6-adapter": "^1.0" }, "autoload": { "psr-4": { diff --git a/docs/reference/FacebookVideo.md b/docs/reference/FacebookVideo.md index df7e424c1..38dbb9b4e 100644 --- a/docs/reference/FacebookVideo.md +++ b/docs/reference/FacebookVideo.md @@ -24,6 +24,8 @@ $myVideoFileToUpload = $fb->videoToUpload('/path/to/video-file.mp4'), Partial file uploads are possible using the `$maxLength` and `$offset` parameters which provide the same functionality as the `$maxlen` and `$offset` parameters on the [`stream_get_contents()` PHP function](http://php.net/stream_get_contents). +> **Warning:** Uploading videos may cause a timeout. Make sure to configure your HTTP client to increase timeout time before uploading videos. + ## Usage In Graph v2.3, functionality was added to [upload video files in chunks](https://developers.facebook.com/docs/graph-api/video-uploads#resumable). The PHP SDK provides a handy API to easily upload video files in chunks via the [`uploadVideo()` method](Facebook.md#uploadvideo). diff --git a/src/Facebook.php b/src/Facebook.php index 7df2005d7..679aaa4f9 100644 --- a/src/Facebook.php +++ b/src/Facebook.php @@ -32,7 +32,6 @@ use Facebook\GraphNodes\GraphEdge; use Facebook\Url\UrlDetectionInterface; use Facebook\Url\FacebookUrlDetectionHandler; -use Facebook\HttpClients\HttpClientsFactory; use Facebook\PersistentData\PersistentDataFactory; use Facebook\PersistentData\PersistentDataInterface; use Facebook\Helpers\FacebookCanvasHelper; @@ -40,6 +39,7 @@ use Facebook\Helpers\FacebookPageTabHelper; use Facebook\Helpers\FacebookRedirectLoginHelper; use Facebook\Exceptions\FacebookSDKException; +use Http\Client\HttpClient; /** * Class Facebook @@ -117,7 +117,7 @@ public function __construct(array $config = []) 'app_secret' => getenv(static::APP_SECRET_ENV_NAME), 'default_graph_version' => null, 'enable_beta_mode' => false, - 'http_client_handler' => null, + 'http_client' => null, 'persistent_data_handler' => null, 'url_detection_handler' => null, ], $config); @@ -128,13 +128,16 @@ public function __construct(array $config = []) if (!$config['app_secret']) { throw new FacebookSDKException('Required "app_secret" key not supplied in config and could not find fallback environment variable "' . static::APP_SECRET_ENV_NAME . '"'); } + if ($config['http_client'] !== null && !$config['http_client'] instanceof HttpClient) { + throw new \InvalidArgumentException('Required "http_client" key to be null or an instance of \Http\Client\HttpClient'); + } if (!$config['default_graph_version']) { throw new \InvalidArgumentException('Required "default_graph_version" key not supplied in config'); } $this->app = new FacebookApp($config['app_id'], $config['app_secret']); $this->client = new FacebookClient( - HttpClientsFactory::createHttpClient($config['http_client_handler']), + $config['http_client'], $config['enable_beta_mode'] ); $this->setUrlDetectionHandler($config['url_detection_handler'] ?: new FacebookUrlDetectionHandler()); diff --git a/src/FacebookClient.php b/src/FacebookClient.php index dbf759238..12904f889 100644 --- a/src/FacebookClient.php +++ b/src/FacebookClient.php @@ -23,10 +23,10 @@ */ namespace Facebook; -use Facebook\HttpClients\FacebookHttpClientInterface; -use Facebook\HttpClients\FacebookCurlHttpClient; -use Facebook\HttpClients\FacebookStreamHttpClient; use Facebook\Exceptions\FacebookSDKException; +use Http\Client\HttpClient; +use Http\Discovery\HttpClientDiscovery; +use Http\Discovery\MessageFactoryDiscovery; /** * Class FacebookClient @@ -76,9 +76,9 @@ class FacebookClient protected $enableBetaMode = false; /** - * @var FacebookHttpClientInterface HTTP client handler. + * @var HttpClient HTTP client handler. */ - protected $httpClientHandler; + protected $httpClient; /** * @var int The number of calls that have been made to Graph. @@ -88,43 +88,33 @@ class FacebookClient /** * Instantiates a new FacebookClient object. * - * @param FacebookHttpClientInterface|null $httpClientHandler - * @param boolean $enableBeta + * @param HttpClient|null $httpClient + * @param boolean $enableBeta */ - public function __construct(FacebookHttpClientInterface $httpClientHandler = null, $enableBeta = false) + public function __construct(HttpClient $httpClient = null, $enableBeta = false) { - $this->httpClientHandler = $httpClientHandler ?: $this->detectHttpClientHandler(); + $this->httpClient = $httpClient ?: HttpClientDiscovery::find(); $this->enableBetaMode = $enableBeta; } /** * Sets the HTTP client handler. * - * @param FacebookHttpClientInterface $httpClientHandler + * @param HttpClient $httpClient */ - public function setHttpClientHandler(FacebookHttpClientInterface $httpClientHandler) + public function setHttpClient(HttpClient $httpClient) { - $this->httpClientHandler = $httpClientHandler; + $this->httpClient = $httpClient; } /** * Returns the HTTP client handler. * - * @return FacebookHttpClientInterface + * @return HttpClient */ - public function getHttpClientHandler() + public function getHttpClient() { - return $this->httpClientHandler; - } - - /** - * Detects which HTTP client handler to use. - * - * @return FacebookHttpClientInterface - */ - public function detectHttpClientHandler() - { - return extension_loaded('curl') ? new FacebookCurlHttpClient() : new FacebookStreamHttpClient(); + return $this->httpClient; } /** @@ -203,32 +193,30 @@ public function sendRequest(FacebookRequest $request) list($url, $method, $headers, $body) = $this->prepareRequestMessage($request); - // Since file uploads can take a while, we need to give more time for uploads - $timeOut = static::DEFAULT_REQUEST_TIMEOUT; - if ($request->containsFileUploads()) { - $timeOut = static::DEFAULT_FILE_UPLOAD_REQUEST_TIMEOUT; - } elseif ($request->containsVideoUploads()) { - $timeOut = static::DEFAULT_VIDEO_UPLOAD_REQUEST_TIMEOUT; - } - - // Should throw `FacebookSDKException` exception on HTTP client error. - // Don't catch to allow it to bubble up. - $rawResponse = $this->httpClientHandler->send($url, $method, $body, $headers, $timeOut); + $psr7Response = $this->httpClient->sendRequest( + MessageFactoryDiscovery::find()->createRequest($method, $url, $headers, $body) + ); static::$requestCount++; - $returnResponse = new FacebookResponse( + // Prepare headers from associative array to a single string for each header. + $responseHeaders = []; + foreach ($psr7Response->getHeaders() as $name => $values) { + $responseHeaders[] = sprintf('%s: %s', $name, implode(", ", $values)); + } + + $facebookResponse = new FacebookResponse( $request, - $rawResponse->getBody(), - $rawResponse->getHttpResponseCode(), - $rawResponse->getHeaders() + $psr7Response->getBody(), + $psr7Response->getStatusCode(), + $responseHeaders ); - if ($returnResponse->isError()) { - throw $returnResponse->getThrownException(); + if ($facebookResponse->isError()) { + throw $facebookResponse->getThrownException(); } - return $returnResponse; + return $facebookResponse; } /** diff --git a/src/Http/GraphRawResponse.php b/src/Http/GraphRawResponse.php deleted file mode 100644 index 4a37b58a2..000000000 --- a/src/Http/GraphRawResponse.php +++ /dev/null @@ -1,137 +0,0 @@ -httpResponseCode = (int)$httpStatusCode; - } - - if (is_array($headers)) { - $this->headers = $headers; - } else { - $this->setHeadersFromString($headers); - } - - $this->body = $body; - } - - /** - * Return the response headers. - * - * @return array - */ - public function getHeaders() - { - return $this->headers; - } - - /** - * Return the body of the response. - * - * @return string - */ - public function getBody() - { - return $this->body; - } - - /** - * Return the HTTP response code. - * - * @return int - */ - public function getHttpResponseCode() - { - return $this->httpResponseCode; - } - - /** - * Sets the HTTP response code from a raw header. - * - * @param string $rawResponseHeader - */ - public function setHttpResponseCodeFromHeader($rawResponseHeader) - { - preg_match('|HTTP/\d\.\d\s+(\d+)\s+.*|', $rawResponseHeader, $match); - $this->httpResponseCode = (int)$match[1]; - } - - /** - * Parse the raw headers and set as an array. - * - * @param string $rawHeaders The raw headers from the response. - */ - protected function setHeadersFromString($rawHeaders) - { - // Normalize line breaks - $rawHeaders = str_replace("\r\n", "\n", $rawHeaders); - - // There will be multiple headers if a 301 was followed - // or a proxy was followed, etc - $headerCollection = explode("\n\n", trim($rawHeaders)); - // We just want the last response (at the end) - $rawHeader = array_pop($headerCollection); - - $headerComponents = explode("\n", $rawHeader); - foreach ($headerComponents as $line) { - if (strpos($line, ': ') === false) { - $this->setHttpResponseCodeFromHeader($line); - } else { - list($key, $value) = explode(': ', $line); - $this->headers[$key] = $value; - } - } - } -} diff --git a/src/HttpClients/FacebookCurl.php b/src/HttpClients/FacebookCurl.php index 28e4ba598..e69de29bb 100644 --- a/src/HttpClients/FacebookCurl.php +++ b/src/HttpClients/FacebookCurl.php @@ -1,129 +0,0 @@ -curl = curl_init(); - } - - /** - * Set a curl option - * - * @param $key - * @param $value - */ - public function setopt($key, $value) - { - curl_setopt($this->curl, $key, $value); - } - - /** - * Set an array of options to a curl resource - * - * @param array $options - */ - public function setoptArray(array $options) - { - curl_setopt_array($this->curl, $options); - } - - /** - * Send a curl request - * - * @return mixed - */ - public function exec() - { - return curl_exec($this->curl); - } - - /** - * Return the curl error number - * - * @return int - */ - public function errno() - { - return curl_errno($this->curl); - } - - /** - * Return the curl error message - * - * @return string - */ - public function error() - { - return curl_error($this->curl); - } - - /** - * Get info from a curl reference - * - * @param $type - * - * @return mixed - */ - public function getinfo($type) - { - return curl_getinfo($this->curl, $type); - } - - /** - * Get the currently installed curl version - * - * @return array - */ - public function version() - { - return curl_version(); - } - - /** - * Close the resource connection to curl - */ - public function close() - { - curl_close($this->curl); - } -} diff --git a/src/HttpClients/FacebookCurlHttpClient.php b/src/HttpClients/FacebookCurlHttpClient.php deleted file mode 100644 index 48bb2088c..000000000 --- a/src/HttpClients/FacebookCurlHttpClient.php +++ /dev/null @@ -1,165 +0,0 @@ -facebookCurl = $facebookCurl ?: new FacebookCurl(); - } - - /** - * @inheritdoc - */ - public function send($url, $method, $body, array $headers, $timeOut) - { - $this->openConnection($url, $method, $body, $headers, $timeOut); - $this->sendRequest(); - - if ($curlErrorCode = $this->facebookCurl->errno()) { - $this->closeConnection(); - - throw new FacebookSDKException($this->facebookCurl->error(), $curlErrorCode); - } - - // Separate the raw headers from the raw body - list($rawHeaders, $rawBody) = $this->extractResponseHeadersAndBody(); - - $this->closeConnection(); - - return new GraphRawResponse($rawHeaders, $rawBody); - } - - /** - * Opens a new curl connection. - * - * @param string $url The endpoint to send the request to. - * @param string $method The request method. - * @param string $body The body of the request. - * @param array $headers The request headers. - * @param int $timeOut The timeout in seconds for the request. - */ - public function openConnection($url, $method, $body, array $headers, $timeOut) - { - $options = [ - CURLOPT_CUSTOMREQUEST => $method, - CURLOPT_HTTPHEADER => $this->compileRequestHeaders($headers), - CURLOPT_URL => $url, - CURLOPT_CONNECTTIMEOUT => 10, - CURLOPT_TIMEOUT => $timeOut, - CURLOPT_RETURNTRANSFER => true, // Follow 301 redirects - CURLOPT_HEADER => true, // Enable header processing - CURLOPT_SSL_VERIFYHOST => 2, - CURLOPT_SSL_VERIFYPEER => true, - CURLOPT_CAINFO => __DIR__ . '/certs/DigiCertHighAssuranceEVRootCA.pem', - ]; - - if ($method !== "GET") { - $options[CURLOPT_POSTFIELDS] = $body; - } - - $this->facebookCurl->init(); - $this->facebookCurl->setoptArray($options); - } - - /** - * Closes an existing curl connection - */ - public function closeConnection() - { - $this->facebookCurl->close(); - } - - /** - * Send the request and get the raw response from curl - */ - public function sendRequest() - { - $this->rawResponse = $this->facebookCurl->exec(); - } - - /** - * Compiles the request headers into a curl-friendly format. - * - * @param array $headers The request headers. - * - * @return array - */ - public function compileRequestHeaders(array $headers) - { - $return = []; - - foreach ($headers as $key => $value) { - $return[] = $key . ': ' . $value; - } - - return $return; - } - - /** - * Extracts the headers and the body into a two-part array - * - * @return array - */ - public function extractResponseHeadersAndBody() - { - $parts = explode("\r\n\r\n", $this->rawResponse); - $rawBody = array_pop($parts); - $rawHeaders = implode("\r\n\r\n", $parts); - - return [trim($rawHeaders), trim($rawBody)]; - } -} diff --git a/src/HttpClients/FacebookGuzzleHttpClient.php b/src/HttpClients/FacebookGuzzleHttpClient.php deleted file mode 100644 index 8feb7cb6d..000000000 --- a/src/HttpClients/FacebookGuzzleHttpClient.php +++ /dev/null @@ -1,97 +0,0 @@ -guzzleClient = $guzzleClient ?: new Client(); - } - - /** - * @inheritdoc - */ - public function send($url, $method, $body, array $headers, $timeOut) - { - $options = [ - 'headers' => $headers, - 'body' => $body, - 'timeout' => $timeOut, - 'connect_timeout' => 10, - 'verify' => __DIR__ . '/certs/DigiCertHighAssuranceEVRootCA.pem', - ]; - $request = $this->guzzleClient->createRequest($method, $url, $options); - - try { - $rawResponse = $this->guzzleClient->send($request); - } catch (RequestException $e) { - $rawResponse = $e->getResponse(); - - if ($e->getPrevious() instanceof RingException || !$rawResponse instanceof ResponseInterface) { - throw new FacebookSDKException($e->getMessage(), $e->getCode()); - } - } - - $rawHeaders = $this->getHeadersAsString($rawResponse); - $rawBody = $rawResponse->getBody(); - $httpStatusCode = $rawResponse->getStatusCode(); - - return new GraphRawResponse($rawHeaders, $rawBody, $httpStatusCode); - } - - /** - * Returns the Guzzle array of headers as a string. - * - * @param ResponseInterface $response The Guzzle response. - * - * @return string - */ - public function getHeadersAsString(ResponseInterface $response) - { - $headers = $response->getHeaders(); - $rawHeaders = []; - foreach ($headers as $name => $values) { - $rawHeaders[] = $name . ": " . implode(", ", $values); - } - - return implode("\r\n", $rawHeaders); - } -} diff --git a/src/HttpClients/FacebookHttpClientInterface.php b/src/HttpClients/FacebookHttpClientInterface.php deleted file mode 100644 index 1fbf953d8..000000000 --- a/src/HttpClients/FacebookHttpClientInterface.php +++ /dev/null @@ -1,47 +0,0 @@ -stream = stream_context_create($options); - } - - /** - * The response headers from the stream wrapper - * - * @return array - */ - public function getResponseHeaders() - { - return $this->responseHeaders; - } - - /** - * Send a stream wrapped request - * - * @param string $url - * - * @return mixed - */ - public function fileGetContents($url) - { - $rawResponse = file_get_contents($url, false, $this->stream); - $this->responseHeaders = $http_response_header ?: []; - - return $rawResponse; - } -} diff --git a/src/HttpClients/FacebookStreamHttpClient.php b/src/HttpClients/FacebookStreamHttpClient.php deleted file mode 100644 index 1cdfd5398..000000000 --- a/src/HttpClients/FacebookStreamHttpClient.php +++ /dev/null @@ -1,94 +0,0 @@ -facebookStream = $facebookStream ?: new FacebookStream(); - } - - /** - * @inheritdoc - */ - public function send($url, $method, $body, array $headers, $timeOut) - { - $options = [ - 'http' => [ - 'method' => $method, - 'header' => $this->compileHeader($headers), - 'content' => $body, - 'timeout' => $timeOut, - 'ignore_errors' => true - ], - 'ssl' => [ - 'verify_peer' => true, - 'verify_peer_name' => true, - 'allow_self_signed' => true, // All root certificates are self-signed - 'cafile' => __DIR__ . '/certs/DigiCertHighAssuranceEVRootCA.pem', - ], - ]; - - $this->facebookStream->streamContextCreate($options); - $rawBody = $this->facebookStream->fileGetContents($url); - $rawHeaders = $this->facebookStream->getResponseHeaders(); - - if ($rawBody === false || empty($rawHeaders)) { - throw new FacebookSDKException('Stream returned an empty response', 660); - } - - $rawHeaders = implode("\r\n", $rawHeaders); - - return new GraphRawResponse($rawHeaders, $rawBody); - } - - /** - * Formats the headers for use in the stream wrapper. - * - * @param array $headers The request headers. - * - * @return string - */ - public function compileHeader(array $headers) - { - $header = []; - foreach ($headers as $k => $v) { - $header[] = $k . ': ' . $v; - } - - return implode("\r\n", $header); - } -} diff --git a/src/HttpClients/HttpClientsFactory.php b/src/HttpClients/HttpClientsFactory.php deleted file mode 100644 index d9f2a8d3d..000000000 --- a/src/HttpClients/HttpClientsFactory.php +++ /dev/null @@ -1,99 +0,0 @@ -fbApp = new FacebookApp('id', 'shhhh!'); - $this->fbClient = new FacebookClient(new MyFooClientHandler()); + $this->fbClient = new FacebookClient(new MyFooHttpClient()); } public function testACustomHttpClientCanBeInjected() { - $handler = new MyFooClientHandler(); + $handler = new MyFooHttpClient(); $client = new FacebookClient($handler); - $httpHandler = $client->getHttpClientHandler(); + $httpClient = $client->getHttpClient(); - $this->assertInstanceOf(MyFooClientHandler::class, $httpHandler); + $this->assertInstanceOf(MyFooHttpClient::class, $httpClient); } public function testTheHttpClientWillFallbackToDefault() { $client = new FacebookClient(); - $httpHandler = $client->getHttpClientHandler(); + $httpClient = $client->getHttpClient(); - if (function_exists('curl_init')) { - $this->assertInstanceOf(FacebookCurlHttpClient::class, $httpHandler); - } else { - $this->assertInstanceOf(FacebookStreamHttpClient::class, $httpHandler); - } + $this->assertInstanceOf(HttpClient::class, $httpClient); } public function testBetaModeCanBeDisabledOrEnabledViaConstructor() @@ -143,7 +140,7 @@ public function testAFacebookBatchRequestEntityCanBeUsedToSendABatchRequestToGra ]; $fbBatchRequest = new FacebookBatchRequest($this->fbApp, $fbRequests); - $fbBatchClient = new FacebookClient(new MyFooBatchClientHandler()); + $fbBatchClient = new FacebookClient(new MyFooBatchHttpClient()); $response = $fbBatchClient->sendBatchRequest($fbBatchRequest); $this->assertInstanceOf(FacebookBatchResponse::class, $response); @@ -281,18 +278,6 @@ public function initializeTestApp() FacebookTestCredentials::$appSecret ); - // Use default client - $client = null; - - // Uncomment to enable curl implementation. - //$client = new FacebookCurlHttpClient(); - - // Uncomment to enable stream wrapper implementation. - //$client = new FacebookStreamHttpClient(); - - // Uncomment to enable Guzzle implementation. - //$client = new FacebookGuzzleHttpClient(); - - static::$testFacebookClient = new FacebookClient($client); + static::$testFacebookClient = new FacebookClient(); } } diff --git a/tests/FacebookTest.php b/tests/FacebookTest.php index d62a5e9c2..4f42d7324 100644 --- a/tests/FacebookTest.php +++ b/tests/FacebookTest.php @@ -29,7 +29,7 @@ use Facebook\Authentication\AccessToken; use Facebook\GraphNodes\GraphEdge; use Facebook\Tests\Fixtures\FakeGraphApiForResumableUpload; -use Facebook\Tests\Fixtures\FooClientInterface; +use Facebook\Tests\Fixtures\FooHttpClientInterface; use Facebook\Tests\Fixtures\FooPersistentDataInterface; use Facebook\Tests\Fixtures\FooUrlDetectionInterface; use Facebook\HttpClients\FacebookCurlHttpClient; @@ -93,53 +93,24 @@ public function testInstantiatingWithoutDefaultGraphVersionThrows() /** * @expectedException \InvalidArgumentException */ - public function testSettingAnInvalidHttpClientHandlerThrows() + public function testSettingAnInvalidHttpClientTypeThrows() { $config = array_merge($this->config, [ - 'http_client_handler' => 'foo_handler', + 'http_client' => 'foo_client', ]); new Facebook($config); } - public function testCurlHttpClientHandlerCanBeForced() - { - if (!extension_loaded('curl')) { - $this->markTestSkipped('cURL must be installed to test cURL client handler.'); - } - $config = array_merge($this->config, [ - 'http_client_handler' => 'curl' - ]); - $fb = new Facebook($config); - $this->assertInstanceOf( - FacebookCurlHttpClient::class, - $fb->getClient()->getHttpClientHandler() - ); - } - - public function testStreamHttpClientHandlerCanBeForced() - { - $config = array_merge($this->config, [ - 'http_client_handler' => 'stream' - ]); - $fb = new Facebook($config); - $this->assertInstanceOf( - FacebookStreamHttpClient::class, - $fb->getClient()->getHttpClientHandler() - ); - } - - public function testGuzzleHttpClientHandlerCanBeForced() + /** + * @expectedException \InvalidArgumentException + */ + public function testSettingAnInvalidHttpClientClassThrows() { $config = array_merge($this->config, [ - 'http_client_handler' => 'guzzle' + 'http_client' => new \stdClass(), ]); - $fb = new Facebook($config); - $this->assertInstanceOf( - FacebookGuzzleHttpClient::class, - $fb->getClient()->getHttpClientHandler() - ); + new Facebook($config); } - /** * @expectedException \InvalidArgumentException */ @@ -234,15 +205,15 @@ public function testCreatingANewRequestWillDefaultToTheProperConfig() public function testCanInjectCustomHandlers() { $config = array_merge($this->config, [ - 'http_client_handler' => new FooClientInterface(), + 'http_client' => new FooHttpClientInterface(), 'persistent_data_handler' => new FooPersistentDataInterface(), 'url_detection_handler' => new FooUrlDetectionInterface(), ]); $fb = new Facebook($config); $this->assertInstanceOf( - FooClientInterface::class, - $fb->getClient()->getHttpClientHandler() + FooHttpClientInterface::class, + $fb->getClient()->getHttpClient() ); $this->assertInstanceOf( FooPersistentDataInterface::class, @@ -257,7 +228,7 @@ public function testCanInjectCustomHandlers() public function testPaginationReturnsProperResponse() { $config = array_merge($this->config, [ - 'http_client_handler' => new FooClientInterface(), + 'http_client' => new FooHttpClientInterface(), ]); $fb = new Facebook($config); @@ -292,7 +263,7 @@ public function testPaginationReturnsProperResponse() public function testCanGetSuccessfulTransferWithMaxTries() { $config = array_merge($this->config, [ - 'http_client_handler' => new FakeGraphApiForResumableUpload(), + 'http_client' => new FakeGraphApiForResumableUpload(), ]); $fb = new Facebook($config); $response = $fb->uploadVideo('me', __DIR__.'/foo.txt', [], 'foo-token', 3); @@ -311,7 +282,7 @@ public function testMaxingOutRetriesWillThrow() $client->failOnTransfer(); $config = array_merge($this->config, [ - 'http_client_handler' => $client, + 'http_client' => $client, ]); $fb = new Facebook($config); $fb->uploadVideo('4', __DIR__.'/foo.txt', [], 'foo-token', 3); diff --git a/tests/Fixtures/FakeGraphApiForResumableUpload.php b/tests/Fixtures/FakeGraphApiForResumableUpload.php index 1c2d0f875..ceec15ee0 100644 --- a/tests/Fixtures/FakeGraphApiForResumableUpload.php +++ b/tests/Fixtures/FakeGraphApiForResumableUpload.php @@ -19,15 +19,15 @@ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. - * */ namespace Facebook\Tests\Fixtures; -use Facebook\Http\GraphRawResponse; -use Facebook\HttpClients\FacebookHttpClientInterface; +use GuzzleHttp\Psr7\Response; +use Http\Client\HttpClient; +use Psr\Http\Message\RequestInterface; -class FakeGraphApiForResumableUpload implements FacebookHttpClientInterface +class FakeGraphApiForResumableUpload implements HttpClient { public $transferCount = 0; private $respondWith = 'SUCCESS'; @@ -42,8 +42,9 @@ public function failOnTransfer() $this->respondWith = 'FAIL_ON_TRANSFER'; } - public function send($url, $method, $body, array $headers, $timeOut) + public function sendRequest(RequestInterface $request) { + $body = $request->getBody()->__toString(); // Could be start, transfer or finish if (strpos($body, 'transfer') !== false) { return $this->respondTransfer(); @@ -57,16 +58,18 @@ public function send($url, $method, $body, array $headers, $timeOut) private function respondStart() { if ($this->respondWith == 'FAIL_ON_START') { - return new GraphRawResponse( - "HTTP/1.1 500 OK\r\nFoo: Bar", - '{"error":{"message":"Error validating access token: Session has expired on Monday, ' . - '10-Aug-15 01:00:00 PDT. The current time is Monday, 10-Aug-15 01:14:23 PDT.",' . + return new Response( + 500, + ['Foo' => 'Bar'], + '{"error":{"message":"Error validating access token: Session has expired on Monday, '. + '10-Aug-15 01:00:00 PDT. The current time is Monday, 10-Aug-15 01:14:23 PDT.",'. '"type":"OAuthException","code":190,"error_subcode":463}}' ); } - return new GraphRawResponse( - "HTTP/1.1 200 OK\r\nFoo: Bar", + return new Response( + 200, + ['Foo' => 'Bar'], '{"video_id":"1337","start_offset":"0","end_offset":"20","upload_session_id":"42"}' ); } @@ -74,9 +77,10 @@ private function respondStart() private function respondTransfer() { if ($this->respondWith == 'FAIL_ON_TRANSFER') { - return new GraphRawResponse( - "HTTP/1.1 500 OK\r\nFoo: Bar", - '{"error":{"message":"There was a problem uploading your video. Please try uploading it again.",' . + return new Response( + 500, + ['Foo' => 'Bar'], + '{"error":{"message":"There was a problem uploading your video. Please try uploading it again.",'. '"type":"FacebookApiException","code":6000,"error_subcode":1363019}}' ); } @@ -95,17 +99,11 @@ private function respondTransfer() $this->transferCount++; - return new GraphRawResponse( - "HTTP/1.1 200 OK\r\nFoo: Bar", - json_encode($data) - ); + return new Response(200, ['Foo' => 'Bar'], json_encode($data)); } private function respondFinish() { - return new GraphRawResponse( - "HTTP/1.1 200 OK\r\nFoo: Bar", - '{"success":true}' - ); + return new Response(500, ['Foo' => 'Bar'], '{"success":true}'); } } diff --git a/tests/Fixtures/FooClientInterface.php b/tests/Fixtures/FooHttpClientInterface.php similarity index 76% rename from tests/Fixtures/FooClientInterface.php rename to tests/Fixtures/FooHttpClientInterface.php index f4548d823..0384313b8 100644 --- a/tests/Fixtures/FooClientInterface.php +++ b/tests/Fixtures/FooHttpClientInterface.php @@ -23,16 +23,20 @@ */ namespace Facebook\Tests\Fixtures; -use Facebook\Http\GraphRawResponse; -use Facebook\HttpClients\FacebookHttpClientInterface; +use GuzzleHttp\Psr7\Response; +use Http\Client\HttpClient; +use Psr\Http\Message\RequestInterface; -class FooClientInterface implements FacebookHttpClientInterface +class FooHttpClientInterface implements HttpClient { - public function send($url, $method, $body, array $headers, $timeOut) + public function sendRequest(RequestInterface $request) { - return new GraphRawResponse( - "HTTP/1.1 1337 OK\r\nDate: Mon, 19 May 2014 18:37:17 GMT", - '{"data":[{"id":"123","name":"Foo"},{"id":"1337","name":"Bar"}]}' + return new Response( + 1337, + ['Date' => 'Mon, 19 May 2014 18:37:17 GMT'], + '{"data":[{"id":"123","name":"Foo"},{"id":"1337","name":"Bar"}]}', + '1.1', + 'OK' ); } } diff --git a/tests/Fixtures/MyFooBatchClientHandler.php b/tests/Fixtures/MyFooBatchHttpClient.php similarity index 78% rename from tests/Fixtures/MyFooBatchClientHandler.php rename to tests/Fixtures/MyFooBatchHttpClient.php index 4a4c9cbbe..c9f090bd9 100644 --- a/tests/Fixtures/MyFooBatchClientHandler.php +++ b/tests/Fixtures/MyFooBatchHttpClient.php @@ -23,15 +23,17 @@ */ namespace Facebook\Tests\Fixtures; -use Facebook\Http\GraphRawResponse; -use Facebook\HttpClients\FacebookHttpClientInterface; +use GuzzleHttp\Psr7\Response; +use Http\Client\HttpClient; +use Psr\Http\Message\RequestInterface; -class MyFooBatchClientHandler implements FacebookHttpClientInterface +class MyFooBatchHttpClient implements HttpClient { - public function send($url, $method, $body, array $headers, $timeOut) + public function sendRequest(RequestInterface $request) { - return new GraphRawResponse( - "HTTP/1.1 200 OK\r\nDate: Mon, 19 May 2014 18:37:17 GMT", + return new Response( + 200, + ['Date' => 'Mon, 19 May 2014 18:37:17 GMT'], '[{"code":"123","body":"Foo"},{"code":"1337","body":"Bar"}]' ); } diff --git a/tests/Fixtures/MyFooClientHandler.php b/tests/Fixtures/MyFooHttpClient.php similarity index 78% rename from tests/Fixtures/MyFooClientHandler.php rename to tests/Fixtures/MyFooHttpClient.php index 346da9e1e..4e6624610 100644 --- a/tests/Fixtures/MyFooClientHandler.php +++ b/tests/Fixtures/MyFooHttpClient.php @@ -23,15 +23,17 @@ */ namespace Facebook\Tests\Fixtures; -use Facebook\Http\GraphRawResponse; -use Facebook\HttpClients\FacebookHttpClientInterface; +use GuzzleHttp\Psr7\Response; +use Http\Client\HttpClient; +use Psr\Http\Message\RequestInterface; -class MyFooClientHandler implements FacebookHttpClientInterface +class MyFooHttpClient implements HttpClient { - public function send($url, $method, $body, array $headers, $timeOut) + public function sendRequest(RequestInterface $request) { - return new GraphRawResponse( - "HTTP/1.1 200 OK\r\nDate: Mon, 19 May 2014 18:37:17 GMT", + return new Response( + 200, + ['Date'=>'Mon, 19 May 2014 18:37:17 GMT'], '{"data":[{"id":"123","name":"Foo"},{"id":"1337","name":"Bar"}]}' ); } diff --git a/tests/Http/GraphRawResponseTest.php b/tests/Http/GraphRawResponseTest.php deleted file mode 100644 index 39d90c7ab..000000000 --- a/tests/Http/GraphRawResponseTest.php +++ /dev/null @@ -1,83 +0,0 @@ - '"9d86b21aa74d74e574bbb35ba13524a52deb96e3"', - 'Content-Type' => 'text/javascript; charset=UTF-8', - 'X-FB-Rev' => '9244768', - 'Date' => 'Mon, 19 May 2014 18:37:17 GMT', - 'X-FB-Debug' => '02QQiffE7JG2rV6i/Agzd0gI2/OOQ2lk5UW0=', - 'Access-Control-Allow-Origin' => '*', - ]; - - public function testCanSetTheHeadersFromAnArray() - { - $myHeaders = [ - 'foo' => 'bar', - 'baz' => 'faz', - ]; - $response = new GraphRawResponse($myHeaders, ''); - $headers = $response->getHeaders(); - - $this->assertEquals($myHeaders, $headers); - } - - public function testCanSetTheHeadersFromAString() - { - $response = new GraphRawResponse($this->fakeRawHeader, ''); - $headers = $response->getHeaders(); - $httpResponseCode = $response->getHttpResponseCode(); - - $this->assertEquals($this->fakeHeadersAsArray, $headers); - $this->assertEquals(200, $httpResponseCode); - } - - public function testWillIgnoreProxyHeaders() - { - $response = new GraphRawResponse($this->fakeRawProxyHeader . $this->fakeRawHeader, ''); - $headers = $response->getHeaders(); - $httpResponseCode = $response->getHttpResponseCode(); - - $this->assertEquals($this->fakeHeadersAsArray, $headers); - $this->assertEquals(200, $httpResponseCode); - } -} diff --git a/tests/HttpClients/AbstractTestHttpClient.php b/tests/HttpClients/AbstractTestHttpClient.php index 68a4f5aed..e69de29bb 100644 --- a/tests/HttpClients/AbstractTestHttpClient.php +++ b/tests/HttpClients/AbstractTestHttpClient.php @@ -1,62 +0,0 @@ - '"9d86b21aa74d74e574bbb35ba13524a52deb96e3"', - 'Content-Type' => 'text/javascript; charset=UTF-8', - 'X-FB-Rev' => '9244768', - 'Pragma' => 'no-cache', - 'Expires' => 'Sat, 01 Jan 2000 00:00:00 GMT', - 'Connection' => 'close', - 'Date' => 'Mon, 19 May 2014 18:37:17 GMT', - 'X-FB-Debug' => '02QQiffE7JG2rV6i/Agzd0gI2/OOQ2lk5UW0=', - 'Content-Length' => '29', - 'Cache-Control' => 'private, no-cache, no-store, must-revalidate', - 'Access-Control-Allow-Origin' => '*', - ]; -} diff --git a/tests/HttpClients/FacebookCurlHttpClientTest.php b/tests/HttpClients/FacebookCurlHttpClientTest.php deleted file mode 100644 index 8e3d4c592..000000000 --- a/tests/HttpClients/FacebookCurlHttpClientTest.php +++ /dev/null @@ -1,214 +0,0 @@ -markTestSkipped('cURL must be installed to test cURL client handler.'); - } - $this->curlMock = $this->prophesize(FacebookCurl::class); - $this->curlClient = new FacebookCurlHttpClient($this->curlMock->reveal()); - } - - public function testCanOpenGetCurlConnection() - { - $this->curlMock->init()->shouldBeCalled(); - $this->curlMock->setoptArray(Argument::that(function ($arg) { - // array_diff() will sometimes trigger error on child-arrays - if (['X-Foo-Header: X-Bar'] !== $arg[CURLOPT_HTTPHEADER]) { - return false; - } - unset($arg[CURLOPT_HTTPHEADER]); - - $caInfo = array_diff($arg, [ - CURLOPT_CUSTOMREQUEST => 'GET', - CURLOPT_URL => 'http://foo.com', - CURLOPT_CONNECTTIMEOUT => 10, - CURLOPT_TIMEOUT => 123, - CURLOPT_RETURNTRANSFER => true, - CURLOPT_HEADER => true, - CURLOPT_SSL_VERIFYHOST => 2, - CURLOPT_SSL_VERIFYPEER => true, - ]); - - if (count($caInfo) !== 1) { - return false; - } - - if (1 !== preg_match('/.+\/certs\/DigiCertHighAssuranceEVRootCA\.pem$/', $caInfo[CURLOPT_CAINFO])) { - return false; - } - - return true; - }))->shouldBeCalled(); - - $this->curlClient->openConnection('http://foo.com', 'GET', 'foo_body', ['X-Foo-Header' => 'X-Bar'], 123); - } - - public function testCanOpenCurlConnectionWithPostBody() - { - $this->curlMock->init()->shouldBeCalled(); - $this->curlMock->setoptArray(Argument::that(function ($arg) { - - // array_diff() will sometimes trigger error on child-arrays - if ([] !== $arg[CURLOPT_HTTPHEADER]) { - return false; - } - unset($arg[CURLOPT_HTTPHEADER]); - - $caInfo = array_diff($arg, [ - CURLOPT_CUSTOMREQUEST => 'POST', - CURLOPT_URL => 'http://bar.com', - CURLOPT_CONNECTTIMEOUT => 10, - CURLOPT_TIMEOUT => 60, - CURLOPT_RETURNTRANSFER => true, - CURLOPT_HEADER => true, - CURLOPT_SSL_VERIFYHOST => 2, - CURLOPT_SSL_VERIFYPEER => true, - CURLOPT_POSTFIELDS => 'baz=bar', - ]); - - if (count($caInfo) !== 1) { - return false; - } - - if (1 !== preg_match('/.+\/certs\/DigiCertHighAssuranceEVRootCA\.pem$/', $caInfo[CURLOPT_CAINFO])) { - return false; - } - - return true; - }))->shouldBeCalled(); - - $this->curlClient->openConnection('http://bar.com', 'POST', 'baz=bar', [], 60); - } - - public function testCanCloseConnection() - { - $this->curlMock->close()->shouldBeCalled(); - - $this->curlClient->closeConnection(); - } - - public function testIsolatesTheHeaderAndBody() - { - $this->curlMock->exec()->willReturn($this->fakeRawHeader . $this->fakeRawBody); - - $this->curlClient->sendRequest(); - list($rawHeader, $rawBody) = $this->curlClient->extractResponseHeadersAndBody(); - - $this->assertEquals($rawHeader, trim($this->fakeRawHeader)); - $this->assertEquals($rawBody, $this->fakeRawBody); - } - - public function testProperlyHandlesProxyHeaders() - { - $rawHeader = $this->fakeRawProxyHeader . $this->fakeRawHeader; - $this->curlMock->exec()->willReturn($rawHeader . $this->fakeRawBody); - - $this->curlClient->sendRequest(); - list($rawHeaders, $rawBody) = $this->curlClient->extractResponseHeadersAndBody(); - - $this->assertEquals($rawHeaders, trim($rawHeader)); - $this->assertEquals($rawBody, $this->fakeRawBody); - } - - public function testProperlyHandlesProxyHeadersWithCurlBug() - { - $rawHeader = $this->fakeRawProxyHeader2 . $this->fakeRawHeader; - $this->curlMock->exec()->willReturn($rawHeader . $this->fakeRawBody); - - $this->curlClient->sendRequest(); - list($rawHeaders, $rawBody) = $this->curlClient->extractResponseHeadersAndBody(); - - $this->assertEquals($rawHeaders, trim($rawHeader)); - $this->assertEquals($rawBody, $this->fakeRawBody); - } - - public function testProperlyHandlesRedirectHeaders() - { - $rawHeader = $this->fakeRawRedirectHeader . $this->fakeRawHeader; - $this->curlMock->exec()->willReturn($rawHeader . $this->fakeRawBody); - - $this->curlClient->sendRequest(); - list($rawHeaders, $rawBody) = $this->curlClient->extractResponseHeadersAndBody(); - - $this->assertEquals($rawHeaders, trim($rawHeader)); - $this->assertEquals($rawBody, $this->fakeRawBody); - } - - public function testCanSendNormalRequest() - { - $this->curlMock->init()->shouldBeCalled(); - $this->curlMock->setoptArray(Argument::type('array'))->shouldBeCalled(); - $this->curlMock->exec()->willReturn($this->fakeRawHeader . $this->fakeRawBody); - $this->curlMock->errno()->shouldBeCalled(); - $this->curlMock->close()->shouldBeCalled(); - - $response = $this->curlClient->send('http://foo.com/', 'GET', '', [], 60); - - $this->assertInstanceOf(GraphRawResponse::class, $response); - $this->assertEquals($this->fakeRawBody, $response->getBody()); - $this->assertEquals($this->fakeHeadersAsArray, $response->getHeaders()); - $this->assertEquals(200, $response->getHttpResponseCode()); - } - - /** - * @expectedException \Facebook\Exceptions\FacebookSDKException - * @expectedExceptionCode 123 - * @expectedExceptionMessage Foo error - */ - public function testThrowsExceptionOnClientError() - { - $this->curlMock->init()->shouldBeCalled(); - $this->curlMock->setoptArray(Argument::type('array'))->shouldBeCalled(); - $this->curlMock->exec()->willReturn(false); - $this->curlMock->errno()->willReturn(123); - $this->curlMock->error()->willReturn('Foo error'); - $this->curlMock->close()->shouldBeCalled(); - - $this->curlClient->send('http://foo.com/', 'GET', '', [], 60); - } -} diff --git a/tests/HttpClients/FacebookGuzzleHttpClientTest.php b/tests/HttpClients/FacebookGuzzleHttpClientTest.php deleted file mode 100644 index 39f9dfc4c..000000000 --- a/tests/HttpClients/FacebookGuzzleHttpClientTest.php +++ /dev/null @@ -1,129 +0,0 @@ -guzzleMock = $this->prophesize(Client::class); - $this->guzzleClient = new FacebookGuzzleHttpClient($this->guzzleMock->reveal()); - } - - public function testCanSendNormalRequest() - { - $request = new Request('GET', 'http://foo.com'); - - $body = Stream::factory($this->fakeRawBody); - $response = new Response(200, $this->fakeHeadersAsArray, $body); - - $this->guzzleMock->createRequest('GET', 'http://foo.com/', Argument::that(function ($arg) { - - // array_diff_assoc() will sometimes trigger error on child-arrays - if (['X-foo' => 'bar'] !== $arg['headers']) { - return false; - } - unset($arg['headers']); - - $caInfo = array_diff_assoc($arg, [ - 'body' => 'foo_body', - 'timeout' => 123, - 'connect_timeout' => 10, - ]); - - if (count($caInfo) !== 1) { - return false; - } - - if (1 !== preg_match('/.+\/certs\/DigiCertHighAssuranceEVRootCA\.pem$/', $caInfo['verify'])) { - return false; - } - - return true; - }))->willReturn($request); - $this->guzzleMock->send($request)->willReturn($response); - - $response = $this->guzzleClient->send('http://foo.com/', 'GET', 'foo_body', ['X-foo' => 'bar'], 123); - - $this->assertInstanceOf(GraphRawResponse::class, $response); - $this->assertEquals($this->fakeRawBody, $response->getBody()); - $this->assertEquals($this->fakeHeadersAsArray, $response->getHeaders()); - $this->assertEquals(200, $response->getHttpResponseCode()); - } - - /** - * @expectedException \Facebook\Exceptions\FacebookSDKException - */ - public function testThrowsExceptionOnClientError() - { - $request = new Request('GET', 'http://foo.com'); - - $this->guzzleMock->createRequest('GET', 'http://foo.com/', Argument::that(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; - }))->willReturn($request); - $this->guzzleMock->send($request)->willThrow(new RequestException('Foo', $request)); - - $this->guzzleClient->send('http://foo.com/', 'GET', 'foo_body', [], 60); - } -} diff --git a/tests/HttpClients/FacebookStreamHttpClientTest.php b/tests/HttpClients/FacebookStreamHttpClientTest.php deleted file mode 100644 index 39e8929e8..000000000 --- a/tests/HttpClients/FacebookStreamHttpClientTest.php +++ /dev/null @@ -1,116 +0,0 @@ -streamMock = $this->prophesize(FacebookStream::class); - $this->streamClient = new FacebookStreamHttpClient($this->streamMock->reveal()); - } - - public function testCanCompileHeader() - { - $headers = [ - 'X-foo' => 'bar', - 'X-bar' => 'faz', - ]; - $header = $this->streamClient->compileHeader($headers); - $this->assertEquals("X-foo: bar\r\nX-bar: faz", $header); - } - - public function testCanSendNormalRequest() - { - $this->streamMock->streamContextCreate(Argument::that(function ($arg) { - if (!isset($arg['http']) || !isset($arg['ssl'])) { - return false; - } - - if ($arg['http'] !== [ - 'method' => 'GET', - 'header' => 'X-foo: bar', - 'content' => 'foo_body', - 'timeout' => 123, - 'ignore_errors' => true, - ] - ) { - return false; - } - - $caInfo = array_diff_assoc($arg['ssl'], [ - 'verify_peer' => true, - 'verify_peer_name' => true, - 'allow_self_signed' => true, - ]); - - if (count($caInfo) !== 1) { - return false; - } - - if (1 !== preg_match('/.+\/certs\/DigiCertHighAssuranceEVRootCA\.pem$/', $caInfo['cafile'])) { - return false; - } - - return true; - }))->shouldBeCalled(); - $this->streamMock->getResponseHeaders()->willReturn(explode("\n", trim($this->fakeRawHeader))); - $this->streamMock->fileGetContents('http://foo.com/')->willReturn($this->fakeRawBody); - - $response = $this->streamClient->send('http://foo.com/', 'GET', 'foo_body', ['X-foo' => 'bar'], 123); - - $this->assertInstanceOf(GraphRawResponse::class, $response); - $this->assertEquals($this->fakeRawBody, $response->getBody()); - $this->assertEquals($this->fakeHeadersAsArray, $response->getHeaders()); - $this->assertEquals(200, $response->getHttpResponseCode()); - } - - /** - * @expectedException \Facebook\Exceptions\FacebookSDKException - */ - public function testThrowsExceptionOnClientError() - { - $this->streamMock->streamContextCreate(Argument::type('array'))->shouldBeCalled(); - $this->streamMock->getResponseHeaders()->willReturn(''); - $this->streamMock->fileGetContents('http://foo.com/')->willReturn(false); - - $this->streamClient->send('http://foo.com/', 'GET', 'foo_body', [], 60); - } -} diff --git a/tests/HttpClients/HttpClientsFactoryTest.php b/tests/HttpClients/HttpClientsFactoryTest.php deleted file mode 100644 index 953bbd810..000000000 --- a/tests/HttpClients/HttpClientsFactoryTest.php +++ /dev/null @@ -1,73 +0,0 @@ -assertInstanceOf(self::COMMON_INTERFACE, $httpClient); - $this->assertInstanceOf($expected, $httpClient); - } - - /** - * @return array - */ - public function httpClientsProvider() - { - $clients = [ - ['guzzle', self::COMMON_NAMESPACE . 'FacebookGuzzleHttpClient'], - ['stream', self::COMMON_NAMESPACE . 'FacebookStreamHttpClient'], - [new Client(), self::COMMON_NAMESPACE . 'FacebookGuzzleHttpClient'], - [new FacebookGuzzleHttpClient(), self::COMMON_NAMESPACE . 'FacebookGuzzleHttpClient'], - [new FacebookStreamHttpClient(), self::COMMON_NAMESPACE . 'FacebookStreamHttpClient'], - [null, self::COMMON_INTERFACE], - ]; - if (extension_loaded('curl')) { - $clients[] = ['curl', self::COMMON_NAMESPACE . 'FacebookCurlHttpClient']; - $clients[] = [new FacebookCurlHttpClient(), self::COMMON_NAMESPACE . 'FacebookCurlHttpClient']; - } - - return $clients; - } -}