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

Commit

Permalink
Merge pull request #594 from localheinz/fix/phpcs
Browse files Browse the repository at this point in the history
Fix: Require test code to also be PSR-2-compliant
  • Loading branch information
SammyK committed May 26, 2016
2 parents 1f20f7e + 1f54c60 commit c57935a
Show file tree
Hide file tree
Showing 25 changed files with 508 additions and 161 deletions.
1 change: 1 addition & 0 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
filter:
paths:
- 'src/*'
- 'tests/*'

tools:
php_code_sniffer:
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ install:
- travis_retry composer install --prefer-dist --no-interaction

script:
- vendor/bin/phpcs src --standard=psr2 -spn
- vendor/bin/phpcs
- vendor/bin/phpunit --coverage-text --exclude-group integration
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ $ composer global require squizlabs/php_codesniffer
Then you can `cd` into the Facebook PHP SDK folder and run Code Sniffer against the `src/` directory.

``` bash
$ ~/.composer/vendor/bin/phpcs src --standard=psr2 -spn
$ ~/.composer/vendor/bin/phpcs
```

**Happy coding**!
7 changes: 7 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0"?>
<ruleset>
<file>src/</file>
<file>tests/</file>
<arg value="spn" />
<rule ref="PSR2" />
</ruleset>
28 changes: 3 additions & 25 deletions tests/FacebookClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,36 +29,14 @@
use Facebook\FacebookRequest;
use Facebook\FacebookBatchRequest;
use Facebook\FacebookClient;
use Facebook\Http\GraphRawResponse;
use Facebook\HttpClients\FacebookHttpClientInterface;
use Facebook\FileUpload\FacebookFile;
use Facebook\FileUpload\FacebookVideo;
// These are needed when you uncomment the HTTP clients below.
use Facebook\HttpClients\FacebookCurlHttpClient;
use Facebook\HttpClients\FacebookGuzzleHttpClient;
use Facebook\HttpClients\FacebookStreamHttpClient;

class MyFooClientHandler implements FacebookHttpClientInterface
{
public function send($url, $method, $body, array $headers, $timeOut)
{
return new GraphRawResponse(
"HTTP/1.1 200 OK\r\nDate: Mon, 19 May 2014 18:37:17 GMT",
'{"data":[{"id":"123","name":"Foo"},{"id":"1337","name":"Bar"}]}'
);
}
}

class MyFooBatchClientHandler implements FacebookHttpClientInterface
{
public function send($url, $method, $body, array $headers, $timeOut)
{
return new GraphRawResponse(
"HTTP/1.1 200 OK\r\nDate: Mon, 19 May 2014 18:37:17 GMT",
'[{"code":"123","body":"Foo"},{"code":"1337","body":"Bar"}]'
);
}
}
use Facebook\Tests\Fixtures\MyFooBatchClientHandler;
use Facebook\Tests\Fixtures\MyFooClientHandler;

class FacebookClientTest extends \PHPUnit_Framework_TestCase
{
Expand Down Expand Up @@ -94,7 +72,7 @@ public function testACustomHttpClientCanBeInjected()
$client = new FacebookClient($handler);
$httpHandler = $client->getHttpClientHandler();

$this->assertInstanceOf('Facebook\Tests\MyFooClientHandler', $httpHandler);
$this->assertInstanceOf('Facebook\Tests\Fixtures\MyFooClientHandler', $httpHandler);
}

public function testTheHttpClientWillFallbackToDefault()
Expand Down
58 changes: 9 additions & 49 deletions tests/FacebookTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,54 +25,14 @@

use Facebook\Facebook;
use Facebook\FacebookClient;
use Facebook\Http\GraphRawResponse;
use Facebook\HttpClients\FacebookHttpClientInterface;
use Facebook\PersistentData\PersistentDataInterface;
use Facebook\Url\UrlDetectionInterface;
use Facebook\PseudoRandomString\PseudoRandomStringGeneratorInterface;
use Facebook\FacebookRequest;
use Facebook\Authentication\AccessToken;
use Facebook\GraphNodes\GraphEdge;
use Facebook\Tests\FakeGraphApi\FakeGraphApiForResumableUpload;

class FooClientInterface implements FacebookHttpClientInterface
{
public function send($url, $method, $body, array $headers, $timeOut)
{
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"}]}'
);
}
}

class FooPersistentDataInterface implements PersistentDataInterface
{
public function get($key)
{
return 'foo';
}

public function set($key, $value)
{
}
}

class FooUrlDetectionInterface implements UrlDetectionInterface
{
public function getCurrentUrl()
{
return 'https://foo.bar';
}
}

class FooBarPseudoRandomStringGenerator implements PseudoRandomStringGeneratorInterface
{
public function getPseudoRandomString($length)
{
return 'csprs123';
}
}
use Facebook\Tests\Fixtures\FakeGraphApiForResumableUpload;
use Facebook\Tests\Fixtures\FooBarPseudoRandomStringGenerator;
use Facebook\Tests\Fixtures\FooClientInterface;
use Facebook\Tests\Fixtures\FooPersistentDataInterface;
use Facebook\Tests\Fixtures\FooUrlDetectionInterface;

class FacebookTest extends \PHPUnit_Framework_TestCase
{
Expand Down Expand Up @@ -336,19 +296,19 @@ public function testCanInjectCustomHandlers()
$fb = new Facebook($config);

$this->assertInstanceOf(
'Facebook\Tests\FooClientInterface',
'Facebook\Tests\Fixtures\FooClientInterface',
$fb->getClient()->getHttpClientHandler()
);
$this->assertInstanceOf(
'Facebook\Tests\FooPersistentDataInterface',
'Facebook\Tests\Fixtures\FooPersistentDataInterface',
$fb->getRedirectLoginHelper()->getPersistentDataHandler()
);
$this->assertInstanceOf(
'Facebook\Tests\FooUrlDetectionInterface',
'Facebook\Tests\Fixtures\FooUrlDetectionInterface',
$fb->getRedirectLoginHelper()->getUrlDetectionHandler()
);
$this->assertInstanceOf(
'Facebook\Tests\FooBarPseudoRandomStringGenerator',
'Facebook\Tests\Fixtures\FooBarPseudoRandomStringGenerator',
$fb->getRedirectLoginHelper()->getPseudoRandomStringGenerator()
);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/FileUpload/FacebookResumableUploaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
use Facebook\FacebookClient;
use Facebook\FileUpload\FacebookResumableUploader;
use Facebook\FileUpload\FacebookTransferChunk;
use Facebook\Tests\FakeGraphApi\FakeGraphApiForResumableUpload;
use Facebook\Tests\Fixtures\FakeGraphApiForResumableUpload;

class FacebookResumableUploaderTest extends \PHPUnit_Framework_TestCase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*
*/

namespace Facebook\Tests\FakeGraphApi;
namespace Facebook\Tests\Fixtures;

use Facebook\Http\GraphRawResponse;
use Facebook\HttpClients\FacebookHttpClientInterface;
Expand Down Expand Up @@ -58,26 +58,26 @@ 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.",' .
'"type":"OAuthException","code":190,"error_subcode":463}}'
"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.",' .
'"type":"OAuthException","code":190,"error_subcode":463}}'
);
}

return new GraphRawResponse(
"HTTP/1.1 200 OK\r\nFoo: Bar",
'{"video_id":"1337","start_offset":"0","end_offset":"20","upload_session_id":"42"}'
"HTTP/1.1 200 OK\r\nFoo: Bar",
'{"video_id":"1337","start_offset":"0","end_offset":"20","upload_session_id":"42"}'
);
}

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.",' .
'"type":"FacebookApiException","code":6000,"error_subcode":1363019}}'
"HTTP/1.1 500 OK\r\nFoo: Bar",
'{"error":{"message":"There was a problem uploading your video. Please try uploading it again.",' .
'"type":"FacebookApiException","code":6000,"error_subcode":1363019}}'
);
}

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

return new GraphRawResponse(
"HTTP/1.1 200 OK\r\nFoo: Bar",
json_encode($data)
"HTTP/1.1 200 OK\r\nFoo: Bar",
json_encode($data)
);
}

private function respondFinish()
{
return new GraphRawResponse(
"HTTP/1.1 200 OK\r\nFoo: Bar",
'{"success":true}'
"HTTP/1.1 200 OK\r\nFoo: Bar",
'{"success":true}'
);
}
}
34 changes: 34 additions & 0 deletions tests/Fixtures/FooBarPseudoRandomStringGenerator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
* Copyright 2016 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\Fixtures;

use Facebook\PseudoRandomString\PseudoRandomStringGeneratorInterface;

class FooBarPseudoRandomStringGenerator implements PseudoRandomStringGeneratorInterface
{
public function getPseudoRandomString($length)
{
return 'csprs123';
}
}
38 changes: 38 additions & 0 deletions tests/Fixtures/FooClientInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
/**
* Copyright 2016 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\Fixtures;

use Facebook\Http\GraphRawResponse;
use Facebook\HttpClients\FacebookHttpClientInterface;

class FooClientInterface implements FacebookHttpClientInterface
{
public function send($url, $method, $body, array $headers, $timeOut)
{
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"}]}'
);
}
}
38 changes: 38 additions & 0 deletions tests/Fixtures/FooPersistentDataInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
/**
* Copyright 2016 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\Fixtures;

use Facebook\PersistentData\PersistentDataInterface;

class FooPersistentDataInterface implements PersistentDataInterface
{
public function get($key)
{
return 'foo';
}

public function set($key, $value)
{
}
}
34 changes: 34 additions & 0 deletions tests/Fixtures/FooPseudoRandomStringGenerator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
* Copyright 2016 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\Fixtures;

use Facebook\PseudoRandomString\PseudoRandomStringGeneratorInterface;

class FooPseudoRandomStringGenerator implements PseudoRandomStringGeneratorInterface
{
public function getPseudoRandomString($length)
{
return 'csprs123';
}
}

0 comments on commit c57935a

Please sign in to comment.