Skip to content

Commit c57935a

Browse files
committed
Merge pull request facebookarchive#594 from localheinz/fix/phpcs
Fix: Require test code to also be PSR-2-compliant
2 parents 1f20f7e + 1f54c60 commit c57935a

25 files changed

+508
-161
lines changed

.scrutinizer.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
filter:
22
paths:
33
- 'src/*'
4+
- 'tests/*'
45

56
tools:
67
php_code_sniffer:

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ install:
2121
- travis_retry composer install --prefer-dist --no-interaction
2222

2323
script:
24-
- vendor/bin/phpcs src --standard=psr2 -spn
24+
- vendor/bin/phpcs
2525
- vendor/bin/phpunit --coverage-text --exclude-group integration

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ $ composer global require squizlabs/php_codesniffer
4848
Then you can `cd` into the Facebook PHP SDK folder and run Code Sniffer against the `src/` directory.
4949

5050
``` bash
51-
$ ~/.composer/vendor/bin/phpcs src --standard=psr2 -spn
51+
$ ~/.composer/vendor/bin/phpcs
5252
```
5353

5454
**Happy coding**!

phpcs.xml.dist

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0"?>
2+
<ruleset>
3+
<file>src/</file>
4+
<file>tests/</file>
5+
<arg value="spn" />
6+
<rule ref="PSR2" />
7+
</ruleset>

tests/FacebookClientTest.php

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,36 +29,14 @@
2929
use Facebook\FacebookRequest;
3030
use Facebook\FacebookBatchRequest;
3131
use Facebook\FacebookClient;
32-
use Facebook\Http\GraphRawResponse;
33-
use Facebook\HttpClients\FacebookHttpClientInterface;
3432
use Facebook\FileUpload\FacebookFile;
3533
use Facebook\FileUpload\FacebookVideo;
3634
// These are needed when you uncomment the HTTP clients below.
3735
use Facebook\HttpClients\FacebookCurlHttpClient;
3836
use Facebook\HttpClients\FacebookGuzzleHttpClient;
3937
use Facebook\HttpClients\FacebookStreamHttpClient;
40-
41-
class MyFooClientHandler implements FacebookHttpClientInterface
42-
{
43-
public function send($url, $method, $body, array $headers, $timeOut)
44-
{
45-
return new GraphRawResponse(
46-
"HTTP/1.1 200 OK\r\nDate: Mon, 19 May 2014 18:37:17 GMT",
47-
'{"data":[{"id":"123","name":"Foo"},{"id":"1337","name":"Bar"}]}'
48-
);
49-
}
50-
}
51-
52-
class MyFooBatchClientHandler implements FacebookHttpClientInterface
53-
{
54-
public function send($url, $method, $body, array $headers, $timeOut)
55-
{
56-
return new GraphRawResponse(
57-
"HTTP/1.1 200 OK\r\nDate: Mon, 19 May 2014 18:37:17 GMT",
58-
'[{"code":"123","body":"Foo"},{"code":"1337","body":"Bar"}]'
59-
);
60-
}
61-
}
38+
use Facebook\Tests\Fixtures\MyFooBatchClientHandler;
39+
use Facebook\Tests\Fixtures\MyFooClientHandler;
6240

6341
class FacebookClientTest extends \PHPUnit_Framework_TestCase
6442
{
@@ -94,7 +72,7 @@ public function testACustomHttpClientCanBeInjected()
9472
$client = new FacebookClient($handler);
9573
$httpHandler = $client->getHttpClientHandler();
9674

97-
$this->assertInstanceOf('Facebook\Tests\MyFooClientHandler', $httpHandler);
75+
$this->assertInstanceOf('Facebook\Tests\Fixtures\MyFooClientHandler', $httpHandler);
9876
}
9977

10078
public function testTheHttpClientWillFallbackToDefault()

tests/FacebookTest.php

Lines changed: 9 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -25,54 +25,14 @@
2525

2626
use Facebook\Facebook;
2727
use Facebook\FacebookClient;
28-
use Facebook\Http\GraphRawResponse;
29-
use Facebook\HttpClients\FacebookHttpClientInterface;
30-
use Facebook\PersistentData\PersistentDataInterface;
31-
use Facebook\Url\UrlDetectionInterface;
32-
use Facebook\PseudoRandomString\PseudoRandomStringGeneratorInterface;
3328
use Facebook\FacebookRequest;
3429
use Facebook\Authentication\AccessToken;
3530
use Facebook\GraphNodes\GraphEdge;
36-
use Facebook\Tests\FakeGraphApi\FakeGraphApiForResumableUpload;
37-
38-
class FooClientInterface implements FacebookHttpClientInterface
39-
{
40-
public function send($url, $method, $body, array $headers, $timeOut)
41-
{
42-
return new GraphRawResponse(
43-
"HTTP/1.1 1337 OK\r\nDate: Mon, 19 May 2014 18:37:17 GMT",
44-
'{"data":[{"id":"123","name":"Foo"},{"id":"1337","name":"Bar"}]}'
45-
);
46-
}
47-
}
48-
49-
class FooPersistentDataInterface implements PersistentDataInterface
50-
{
51-
public function get($key)
52-
{
53-
return 'foo';
54-
}
55-
56-
public function set($key, $value)
57-
{
58-
}
59-
}
60-
61-
class FooUrlDetectionInterface implements UrlDetectionInterface
62-
{
63-
public function getCurrentUrl()
64-
{
65-
return 'https://foo.bar';
66-
}
67-
}
68-
69-
class FooBarPseudoRandomStringGenerator implements PseudoRandomStringGeneratorInterface
70-
{
71-
public function getPseudoRandomString($length)
72-
{
73-
return 'csprs123';
74-
}
75-
}
31+
use Facebook\Tests\Fixtures\FakeGraphApiForResumableUpload;
32+
use Facebook\Tests\Fixtures\FooBarPseudoRandomStringGenerator;
33+
use Facebook\Tests\Fixtures\FooClientInterface;
34+
use Facebook\Tests\Fixtures\FooPersistentDataInterface;
35+
use Facebook\Tests\Fixtures\FooUrlDetectionInterface;
7636

7737
class FacebookTest extends \PHPUnit_Framework_TestCase
7838
{
@@ -336,19 +296,19 @@ public function testCanInjectCustomHandlers()
336296
$fb = new Facebook($config);
337297

338298
$this->assertInstanceOf(
339-
'Facebook\Tests\FooClientInterface',
299+
'Facebook\Tests\Fixtures\FooClientInterface',
340300
$fb->getClient()->getHttpClientHandler()
341301
);
342302
$this->assertInstanceOf(
343-
'Facebook\Tests\FooPersistentDataInterface',
303+
'Facebook\Tests\Fixtures\FooPersistentDataInterface',
344304
$fb->getRedirectLoginHelper()->getPersistentDataHandler()
345305
);
346306
$this->assertInstanceOf(
347-
'Facebook\Tests\FooUrlDetectionInterface',
307+
'Facebook\Tests\Fixtures\FooUrlDetectionInterface',
348308
$fb->getRedirectLoginHelper()->getUrlDetectionHandler()
349309
);
350310
$this->assertInstanceOf(
351-
'Facebook\Tests\FooBarPseudoRandomStringGenerator',
311+
'Facebook\Tests\Fixtures\FooBarPseudoRandomStringGenerator',
352312
$fb->getRedirectLoginHelper()->getPseudoRandomStringGenerator()
353313
);
354314
}

tests/FileUpload/FacebookResumableUploaderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
use Facebook\FacebookClient;
3030
use Facebook\FileUpload\FacebookResumableUploader;
3131
use Facebook\FileUpload\FacebookTransferChunk;
32-
use Facebook\Tests\FakeGraphApi\FakeGraphApiForResumableUpload;
32+
use Facebook\Tests\Fixtures\FakeGraphApiForResumableUpload;
3333

3434
class FacebookResumableUploaderTest extends \PHPUnit_Framework_TestCase
3535
{

tests/FakeGraphApi/FakeGraphApiForResumableUpload.php renamed to tests/Fixtures/FakeGraphApiForResumableUpload.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*
2323
*/
2424

25-
namespace Facebook\Tests\FakeGraphApi;
25+
namespace Facebook\Tests\Fixtures;
2626

2727
use Facebook\Http\GraphRawResponse;
2828
use Facebook\HttpClients\FacebookHttpClientInterface;
@@ -58,26 +58,26 @@ private function respondStart()
5858
{
5959
if ($this->respondWith == 'FAIL_ON_START') {
6060
return new GraphRawResponse(
61-
"HTTP/1.1 500 OK\r\nFoo: Bar",
62-
'{"error":{"message":"Error validating access token: Session has expired on Monday, ' .
63-
'10-Aug-15 01:00:00 PDT. The current time is Monday, 10-Aug-15 01:14:23 PDT.",' .
64-
'"type":"OAuthException","code":190,"error_subcode":463}}'
61+
"HTTP/1.1 500 OK\r\nFoo: Bar",
62+
'{"error":{"message":"Error validating access token: Session has expired on Monday, ' .
63+
'10-Aug-15 01:00:00 PDT. The current time is Monday, 10-Aug-15 01:14:23 PDT.",' .
64+
'"type":"OAuthException","code":190,"error_subcode":463}}'
6565
);
6666
}
6767

6868
return new GraphRawResponse(
69-
"HTTP/1.1 200 OK\r\nFoo: Bar",
70-
'{"video_id":"1337","start_offset":"0","end_offset":"20","upload_session_id":"42"}'
69+
"HTTP/1.1 200 OK\r\nFoo: Bar",
70+
'{"video_id":"1337","start_offset":"0","end_offset":"20","upload_session_id":"42"}'
7171
);
7272
}
7373

7474
private function respondTransfer()
7575
{
7676
if ($this->respondWith == 'FAIL_ON_TRANSFER') {
7777
return new GraphRawResponse(
78-
"HTTP/1.1 500 OK\r\nFoo: Bar",
79-
'{"error":{"message":"There was a problem uploading your video. Please try uploading it again.",' .
80-
'"type":"FacebookApiException","code":6000,"error_subcode":1363019}}'
78+
"HTTP/1.1 500 OK\r\nFoo: Bar",
79+
'{"error":{"message":"There was a problem uploading your video. Please try uploading it again.",' .
80+
'"type":"FacebookApiException","code":6000,"error_subcode":1363019}}'
8181
);
8282
}
8383

@@ -96,16 +96,16 @@ private function respondTransfer()
9696
$this->transferCount++;
9797

9898
return new GraphRawResponse(
99-
"HTTP/1.1 200 OK\r\nFoo: Bar",
100-
json_encode($data)
99+
"HTTP/1.1 200 OK\r\nFoo: Bar",
100+
json_encode($data)
101101
);
102102
}
103103

104104
private function respondFinish()
105105
{
106106
return new GraphRawResponse(
107-
"HTTP/1.1 200 OK\r\nFoo: Bar",
108-
'{"success":true}'
107+
"HTTP/1.1 200 OK\r\nFoo: Bar",
108+
'{"success":true}'
109109
);
110110
}
111111
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
/**
3+
* Copyright 2016 Facebook, Inc.
4+
*
5+
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
6+
* use, copy, modify, and distribute this software in source code or binary
7+
* form for use in connection with the web services and APIs provided by
8+
* Facebook.
9+
*
10+
* As with any software that integrates with the Facebook platform, your use
11+
* of this software is subject to the Facebook Developer Principles and
12+
* Policies [http://developers.facebook.com/policy/]. This copyright notice
13+
* shall be included in all copies or substantial portions of the software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21+
* DEALINGS IN THE SOFTWARE.
22+
*
23+
*/
24+
namespace Facebook\Tests\Fixtures;
25+
26+
use Facebook\PseudoRandomString\PseudoRandomStringGeneratorInterface;
27+
28+
class FooBarPseudoRandomStringGenerator implements PseudoRandomStringGeneratorInterface
29+
{
30+
public function getPseudoRandomString($length)
31+
{
32+
return 'csprs123';
33+
}
34+
}

tests/Fixtures/FooClientInterface.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/**
3+
* Copyright 2016 Facebook, Inc.
4+
*
5+
* You are hereby granted a non-exclusive, worldwide, royalty-free license to
6+
* use, copy, modify, and distribute this software in source code or binary
7+
* form for use in connection with the web services and APIs provided by
8+
* Facebook.
9+
*
10+
* As with any software that integrates with the Facebook platform, your use
11+
* of this software is subject to the Facebook Developer Principles and
12+
* Policies [http://developers.facebook.com/policy/]. This copyright notice
13+
* shall be included in all copies or substantial portions of the software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21+
* DEALINGS IN THE SOFTWARE.
22+
*
23+
*/
24+
namespace Facebook\Tests\Fixtures;
25+
26+
use Facebook\Http\GraphRawResponse;
27+
use Facebook\HttpClients\FacebookHttpClientInterface;
28+
29+
class FooClientInterface implements FacebookHttpClientInterface
30+
{
31+
public function send($url, $method, $body, array $headers, $timeOut)
32+
{
33+
return new GraphRawResponse(
34+
"HTTP/1.1 1337 OK\r\nDate: Mon, 19 May 2014 18:37:17 GMT",
35+
'{"data":[{"id":"123","name":"Foo"},{"id":"1337","name":"Bar"}]}'
36+
);
37+
}
38+
}

0 commit comments

Comments
 (0)