summaryrefslogtreecommitdiff
path: root/lib/facebook-graph-sdk/tests/HttpClients
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2018-04-26 01:00:12 +0200
committeremkael <emkael@tlen.pl>2018-04-26 01:00:12 +0200
commit4b8a9a5189a625bf99fedec7fd31f6e146410a14 (patch)
treea29759d5f0f0c29f07c89c59f6b5cf38407d1470 /lib/facebook-graph-sdk/tests/HttpClients
parentab82beef33f4c196383a81213dcdff4ebe9447ae (diff)
Update FB API library
Diffstat (limited to 'lib/facebook-graph-sdk/tests/HttpClients')
-rw-r--r--lib/facebook-graph-sdk/tests/HttpClients/AbstractTestHttpClient.php2
-rw-r--r--lib/facebook-graph-sdk/tests/HttpClients/FacebookCurlHttpClientTest.php61
-rw-r--r--lib/facebook-graph-sdk/tests/HttpClients/FacebookGuzzleHttpClientTest.php4
-rw-r--r--lib/facebook-graph-sdk/tests/HttpClients/FacebookStreamHttpClientTest.php4
-rw-r--r--lib/facebook-graph-sdk/tests/HttpClients/HttpClientsFactoryTest.php72
5 files changed, 82 insertions, 61 deletions
diff --git a/lib/facebook-graph-sdk/tests/HttpClients/AbstractTestHttpClient.php b/lib/facebook-graph-sdk/tests/HttpClients/AbstractTestHttpClient.php
index 269b235..a870052 100644
--- a/lib/facebook-graph-sdk/tests/HttpClients/AbstractTestHttpClient.php
+++ b/lib/facebook-graph-sdk/tests/HttpClients/AbstractTestHttpClient.php
@@ -1,6 +1,6 @@
<?php
/**
- * Copyright 2014 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
*
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
* use, copy, modify, and distribute this software in source code or binary
diff --git a/lib/facebook-graph-sdk/tests/HttpClients/FacebookCurlHttpClientTest.php b/lib/facebook-graph-sdk/tests/HttpClients/FacebookCurlHttpClientTest.php
index 4cf31d3..47cc027 100644
--- a/lib/facebook-graph-sdk/tests/HttpClients/FacebookCurlHttpClientTest.php
+++ b/lib/facebook-graph-sdk/tests/HttpClients/FacebookCurlHttpClientTest.php
@@ -1,6 +1,6 @@
<?php
/**
- * Copyright 2014 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
*
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
* use, copy, modify, and distribute this software in source code or binary
@@ -41,8 +41,11 @@ class FacebookCurlHttpClientTest extends AbstractTestHttpClient
const CURL_VERSION_STABLE = 0x072400;
const CURL_VERSION_BUGGY = 0x071400;
- public function setUp()
+ protected function setUp()
{
+ if (!extension_loaded('curl')) {
+ $this->markTestSkipped('cURL must be installed to test cURL client handler.');
+ }
$this->curlMock = m::mock('Facebook\HttpClients\FacebookCurl');
$this->curlClient = new FacebookCurlHttpClient($this->curlMock);
}
@@ -147,15 +150,6 @@ class FacebookCurlHttpClientTest extends AbstractTestHttpClient
public function testIsolatesTheHeaderAndBody()
{
$this->curlMock
- ->shouldReceive('getinfo')
- ->with(CURLINFO_HEADER_SIZE)
- ->once()
- ->andReturn(strlen($this->fakeRawHeader));
- $this->curlMock
- ->shouldReceive('version')
- ->once()
- ->andReturn(['version_number' => self::CURL_VERSION_STABLE]);
- $this->curlMock
->shouldReceive('exec')
->once()
->andReturn($this->fakeRawHeader . $this->fakeRawBody);
@@ -171,15 +165,6 @@ class FacebookCurlHttpClientTest extends AbstractTestHttpClient
{
$rawHeader = $this->fakeRawProxyHeader . $this->fakeRawHeader;
$this->curlMock
- ->shouldReceive('getinfo')
- ->with(CURLINFO_HEADER_SIZE)
- ->once()
- ->andReturn(mb_strlen($rawHeader));
- $this->curlMock
- ->shouldReceive('version')
- ->once()
- ->andReturn(['version_number' => self::CURL_VERSION_STABLE]);
- $this->curlMock
->shouldReceive('exec')
->once()
->andReturn($rawHeader . $this->fakeRawBody);
@@ -195,15 +180,6 @@ class FacebookCurlHttpClientTest extends AbstractTestHttpClient
{
$rawHeader = $this->fakeRawProxyHeader . $this->fakeRawHeader;
$this->curlMock
- ->shouldReceive('getinfo')
- ->with(CURLINFO_HEADER_SIZE)
- ->once()
- ->andReturn(mb_strlen($this->fakeRawHeader)); // Mimic bug that doesn't count proxy header
- $this->curlMock
- ->shouldReceive('version')
- ->once()
- ->andReturn(['version_number' => self::CURL_VERSION_BUGGY]);
- $this->curlMock
->shouldReceive('exec')
->once()
->andReturn($rawHeader . $this->fakeRawBody);
@@ -219,15 +195,6 @@ class FacebookCurlHttpClientTest extends AbstractTestHttpClient
{
$rawHeader = $this->fakeRawProxyHeader2 . $this->fakeRawHeader;
$this->curlMock
- ->shouldReceive('getinfo')
- ->with(CURLINFO_HEADER_SIZE)
- ->once()
- ->andReturn(mb_strlen($this->fakeRawHeader)); // Mimic bug that doesn't count proxy header
- $this->curlMock
- ->shouldReceive('version')
- ->once()
- ->andReturn(['version_number' => self::CURL_VERSION_BUGGY]);
- $this->curlMock
->shouldReceive('exec')
->once()
->andReturn($rawHeader . $this->fakeRawBody);
@@ -243,15 +210,6 @@ class FacebookCurlHttpClientTest extends AbstractTestHttpClient
{
$rawHeader = $this->fakeRawRedirectHeader . $this->fakeRawHeader;
$this->curlMock
- ->shouldReceive('getinfo')
- ->with(CURLINFO_HEADER_SIZE)
- ->once()
- ->andReturn(mb_strlen($rawHeader));
- $this->curlMock
- ->shouldReceive('version')
- ->once()
- ->andReturn(['version_number' => self::CURL_VERSION_STABLE]);
- $this->curlMock
->shouldReceive('exec')
->once()
->andReturn($rawHeader . $this->fakeRawBody);
@@ -282,15 +240,6 @@ class FacebookCurlHttpClientTest extends AbstractTestHttpClient
->once()
->andReturn(null);
$this->curlMock
- ->shouldReceive('getinfo')
- ->with(CURLINFO_HEADER_SIZE)
- ->once()
- ->andReturn(mb_strlen($this->fakeRawHeader));
- $this->curlMock
- ->shouldReceive('version')
- ->once()
- ->andReturn(['version_number' => self::CURL_VERSION_STABLE]);
- $this->curlMock
->shouldReceive('close')
->once()
->andReturn(null);
diff --git a/lib/facebook-graph-sdk/tests/HttpClients/FacebookGuzzleHttpClientTest.php b/lib/facebook-graph-sdk/tests/HttpClients/FacebookGuzzleHttpClientTest.php
index 12eb36a..f14ad96 100644
--- a/lib/facebook-graph-sdk/tests/HttpClients/FacebookGuzzleHttpClientTest.php
+++ b/lib/facebook-graph-sdk/tests/HttpClients/FacebookGuzzleHttpClientTest.php
@@ -1,6 +1,6 @@
<?php
/**
- * Copyright 2014 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
*
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
* use, copy, modify, and distribute this software in source code or binary
@@ -42,7 +42,7 @@ class FacebookGuzzleHttpClientTest extends AbstractTestHttpClient
*/
protected $guzzleClient;
- public function setUp()
+ protected function setUp()
{
$this->guzzleMock = m::mock('GuzzleHttp\Client');
$this->guzzleClient = new FacebookGuzzleHttpClient($this->guzzleMock);
diff --git a/lib/facebook-graph-sdk/tests/HttpClients/FacebookStreamHttpClientTest.php b/lib/facebook-graph-sdk/tests/HttpClients/FacebookStreamHttpClientTest.php
index 9102b08..3749960 100644
--- a/lib/facebook-graph-sdk/tests/HttpClients/FacebookStreamHttpClientTest.php
+++ b/lib/facebook-graph-sdk/tests/HttpClients/FacebookStreamHttpClientTest.php
@@ -1,6 +1,6 @@
<?php
/**
- * Copyright 2014 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
*
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
* use, copy, modify, and distribute this software in source code or binary
@@ -38,7 +38,7 @@ class FacebookStreamHttpClientTest extends AbstractTestHttpClient
*/
protected $streamClient;
- public function setUp()
+ protected function setUp()
{
$this->streamMock = m::mock('Facebook\HttpClients\FacebookStream');
$this->streamClient = new FacebookStreamHttpClient($this->streamMock);
diff --git a/lib/facebook-graph-sdk/tests/HttpClients/HttpClientsFactoryTest.php b/lib/facebook-graph-sdk/tests/HttpClients/HttpClientsFactoryTest.php
new file mode 100644
index 0000000..4d49489
--- /dev/null
+++ b/lib/facebook-graph-sdk/tests/HttpClients/HttpClientsFactoryTest.php
@@ -0,0 +1,72 @@
+<?php
+/**
+ * Copyright 2017 Facebook, Inc.
+ *
+ * You are hereby granted a non-exclusive, worldwide, royalty-free license to
+ * use, copy, modify, and distribute this software in source code or binary
+ * form for use in connection with the web services and APIs provided by
+ * Facebook.
+ *
+ * As with any software that integrates with the Facebook platform, your use
+ * of this software is subject to the Facebook Developer Principles and
+ * Policies [http://developers.facebook.com/policy/]. This copyright notice
+ * shall be included in all copies or substantial portions of the software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * 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\HttpClients;
+
+use Facebook\HttpClients\FacebookCurlHttpClient;
+use Facebook\HttpClients\FacebookGuzzleHttpClient;
+use Facebook\HttpClients\FacebookStreamHttpClient;
+use Facebook\HttpClients\HttpClientsFactory;
+use GuzzleHttp\Client;
+use PHPUnit_Framework_TestCase;
+
+class HttpClientsFactoryTest extends PHPUnit_Framework_TestCase
+{
+ const COMMON_NAMESPACE = 'Facebook\HttpClients\\';
+ const COMMON_INTERFACE = 'Facebook\HttpClients\FacebookHttpClientInterface';
+
+ /**
+ * @param mixed $handler
+ * @param string $expected
+ *
+ * @dataProvider httpClientsProvider
+ */
+ public function testCreateHttpClient($handler, $expected)
+ {
+ $httpClient = HttpClientsFactory::createHttpClient($handler);
+
+ $this->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;
+ }
+}