Skip to content
This repository was archived by the owner on Jan 13, 2022. It is now read-only.

Commit d3b3550

Browse files
committed
Minor fixes and CS
1 parent d8903d5 commit d3b3550

File tree

8 files changed

+51
-20
lines changed

8 files changed

+51
-20
lines changed

composer.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717
"php-http/client-implementation": "^1.0",
1818
"php-http/httplug": "^1.0",
1919
"php-http/discovery": "^1.0",
20-
"paragonie/random_compat": "^2.0"
20+
"paragonie/random_compat": "^2.0",
21+
"squizlabs/php_codesniffer": "^2.7"
2122
},
2223
"require-dev": {
23-
"phpunit/phpunit": "~4.0",
24-
"mockery/mockery": "~0.8",
24+
"phpunit/phpunit": "^4.8 || ^5.6",
25+
"mockery/mockery": "^0.9",
2526
"php-http/guzzle6-adapter": "^1.0",
2627
"php-http/message": "^1.0",
2728
"guzzlehttp/psr7": "^1.0"

docs/FacebookVideo.fbmd

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ $myVideoFileToUpload = $fb->videoToUpload('/path/to/video-file.mp4'),
2828
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).
2929
</card>
3030

31+
%FB(devsite:markdown-wiki:info-card {
32+
content: "Uploading videos may cause a timeout. Make sure to configure your HTTP client to increase timeout time before uploading videos.",
33+
type: 'warning',
34+
})
35+
3136
<card>
3237
## Usage {#usage}
3338

src/Facebook/FacebookClient.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,18 +198,24 @@ public function sendRequest(FacebookRequest $request)
198198

199199
static::$requestCount++;
200200

201-
$returnResponse = new FacebookResponse(
201+
// Prepare headers from associative array to a single string for each header.
202+
$responseHeaders = [];
203+
foreach ($psr7Response->getHeaders() as $name => $values) {
204+
$responseHeaders[] = sprintf('%s: %s', $name, implode(", ", $values));
205+
}
206+
207+
$facebookResponse = new FacebookResponse(
202208
$request,
203209
$psr7Response->getBody(),
204210
$psr7Response->getStatusCode(),
205-
$psr7Response->getHeaders()
211+
$responseHeaders
206212
);
207213

208-
if ($returnResponse->isError()) {
209-
throw $returnResponse->getThrownException();
214+
if ($facebookResponse->isError()) {
215+
throw $facebookResponse->getThrownException();
210216
}
211217

212-
return $returnResponse;
218+
return $facebookResponse;
213219
}
214220

215221
/**

tests/FacebookClientTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ public function testACustomHttpClientCanBeInjected()
7575
$this->assertInstanceOf('Facebook\Tests\Fixtures\MyFooClientHandler', $httpHandler);
7676
}
7777

78+
public function testTheHttpClientWillFallbackToDefault()
79+
{
80+
$client = new FacebookClient();
81+
$httpHandler = $client->getHttpClient();
82+
83+
$this->assertInstanceOf('Http\Client\HttpClient', $httpHandler);
84+
}
85+
7886
public function testBetaModeCanBeDisabledOrEnabledViaConstructor()
7987
{
8088
$client = new FacebookClient(null, false);

tests/Fixtures/FakeGraphApiForResumableUpload.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
2020
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
2121
* DEALINGS IN THE SOFTWARE.
22-
*
2322
*/
2423

2524
namespace Facebook\Tests\Fixtures;
@@ -59,23 +58,29 @@ public function sendRequest(RequestInterface $request)
5958
private function respondStart()
6059
{
6160
if ($this->respondWith == 'FAIL_ON_START') {
62-
return new Response(500, ['Foo'=>'Bar'],
63-
'{"error":{"message":"Error validating access token: Session has expired on Monday, ' .
64-
'10-Aug-15 01:00:00 PDT. The current time is Monday, 10-Aug-15 01:14:23 PDT.",' .
61+
return new Response(
62+
500,
63+
['Foo' => 'Bar'],
64+
'{"error":{"message":"Error validating access token: Session has expired on Monday, '.
65+
'10-Aug-15 01:00:00 PDT. The current time is Monday, 10-Aug-15 01:14:23 PDT.",'.
6566
'"type":"OAuthException","code":190,"error_subcode":463}}'
6667
);
6768
}
6869

69-
return new Response(200, ['Foo'=>'Bar'],
70+
return new Response(
71+
200,
72+
['Foo' => 'Bar'],
7073
'{"video_id":"1337","start_offset":"0","end_offset":"20","upload_session_id":"42"}'
7174
);
7275
}
7376

7477
private function respondTransfer()
7578
{
7679
if ($this->respondWith == 'FAIL_ON_TRANSFER') {
77-
return new Response(500, ['Foo'=>'Bar'],
78-
'{"error":{"message":"There was a problem uploading your video. Please try uploading it again.",' .
80+
return new Response(
81+
500,
82+
['Foo' => 'Bar'],
83+
'{"error":{"message":"There was a problem uploading your video. Please try uploading it again.",'.
7984
'"type":"FacebookApiException","code":6000,"error_subcode":1363019}}'
8085
);
8186
}
@@ -94,11 +99,11 @@ private function respondTransfer()
9499

95100
$this->transferCount++;
96101

97-
return new Response(200, ['Foo'=>'Bar'], json_encode($data));
102+
return new Response(200, ['Foo' => 'Bar'], json_encode($data));
98103
}
99104

100105
private function respondFinish()
101106
{
102-
return new Response(500, ['Foo'=>'Bar'], '{"success":true}');
107+
return new Response(500, ['Foo' => 'Bar'], '{"success":true}');
103108
}
104109
}

tests/Fixtures/FooClientInterface.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ class FooClientInterface implements HttpClient
3131
{
3232
public function sendRequest(RequestInterface $request)
3333
{
34-
return new Response(1337, ['Date' => 'Mon, 19 May 2014 18:37:17 GMT'],
34+
return new Response(
35+
1337,
36+
['Date' => 'Mon, 19 May 2014 18:37:17 GMT'],
3537
'{"data":[{"id":"123","name":"Foo"},{"id":"1337","name":"Bar"}]}',
3638
'1.1',
3739
'OK'

tests/Fixtures/MyFooBatchClientHandler.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ class MyFooBatchClientHandler implements HttpClient
3131
{
3232
public function sendRequest(RequestInterface $request)
3333
{
34-
return new Response(200, ['Date' => 'Mon, 19 May 2014 18:37:17 GMT'],
34+
return new Response(
35+
200,
36+
['Date' => 'Mon, 19 May 2014 18:37:17 GMT'],
3537
'[{"code":"123","body":"Foo"},{"code":"1337","body":"Bar"}]'
3638
);
3739
}

tests/Fixtures/MyFooClientHandler.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ class MyFooClientHandler implements HttpClient
3131
{
3232
public function sendRequest(RequestInterface $request)
3333
{
34-
return new Response(200, ['Date'=>'Mon, 19 May 2014 18:37:17 GMT'],
34+
return new Response(
35+
200,
36+
['Date'=>'Mon, 19 May 2014 18:37:17 GMT'],
3537
'{"data":[{"id":"123","name":"Foo"},{"id":"1337","name":"Bar"}]}'
3638
);
3739
}

0 commit comments

Comments
 (0)