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

Commit 2b4776b

Browse files
added changelog and tests
1 parent fb4de4f commit 2b4776b

File tree

4 files changed

+200
-0
lines changed

4 files changed

+200
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Version 5 of the Facebook PHP SDK is a complete refactor of version 4. It comes
3434
- Renamed `FacebookHttpable` to `FacebookHttpClientInterface`
3535
- Added `FacebookApp` entity that contains info about the Facebook app
3636
- Updated the API for the helpers
37+
- Added `HttpClients`, `PersistentData` and `PseudoRandomString` factories to reduce main class' complexity
3738
- Tests
3839
- Added namespaces to the tests
3940
- Grouped functional tests under `functional` group
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
/**
3+
* Copyright 2014 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\HttpClients;
25+
26+
use Facebook\HttpClients\FacebookCurlHttpClient;
27+
use Facebook\HttpClients\FacebookGuzzleHttpClient;
28+
use Facebook\HttpClients\FacebookStreamHttpClient;
29+
use Facebook\HttpClients\HttpClientsFactory;
30+
use GuzzleHttp\Client;
31+
use PHPUnit_Framework_TestCase;
32+
33+
class HttpClientsFactoryTest extends PHPUnit_Framework_TestCase
34+
{
35+
const COMMON_NAMESPACE = 'Facebook\HttpClients\\';
36+
const COMMON_INTERFACE = 'Facebook\HttpClients\FacebookHttpClientInterface';
37+
38+
/**
39+
* @param mixed $handler
40+
* @param string $expected
41+
*
42+
* @dataProvider httpClientsProvider
43+
*/
44+
public function testCreateHttpClient($handler, $expected)
45+
{
46+
$httpClient = HttpClientsFactory::createHttpClient($handler);
47+
48+
$this->assertInstanceOf(self::COMMON_INTERFACE, $httpClient);
49+
$this->assertInstanceOf($expected, $httpClient);
50+
}
51+
52+
/**
53+
* @return array
54+
*/
55+
public function httpClientsProvider()
56+
{
57+
return [
58+
['curl', self::COMMON_NAMESPACE . 'FacebookCurlHttpClient'],
59+
['guzzle', self::COMMON_NAMESPACE . 'FacebookGuzzleHttpClient'],
60+
['stream', self::COMMON_NAMESPACE . 'FacebookStreamHttpClient'],
61+
[new Client(), self::COMMON_NAMESPACE . 'FacebookGuzzleHttpClient'],
62+
[new FacebookCurlHttpClient(), self::COMMON_NAMESPACE . 'FacebookCurlHttpClient'],
63+
[new FacebookGuzzleHttpClient(), self::COMMON_NAMESPACE . 'FacebookGuzzleHttpClient'],
64+
[new FacebookStreamHttpClient(), self::COMMON_NAMESPACE . 'FacebookStreamHttpClient'],
65+
[null, self::COMMON_INTERFACE],
66+
];
67+
}
68+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
/**
3+
* Copyright 2014 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\PersistentData;
25+
26+
use Facebook\PersistentData\FacebookMemoryPersistentDataHandler;
27+
use Facebook\PersistentData\FacebookSessionPersistentDataHandler;
28+
use Facebook\PersistentData\PersistentDataFactory;
29+
use PHPUnit_Framework_TestCase;
30+
31+
class PersistentDataFactoryTest extends PHPUnit_Framework_TestCase
32+
{
33+
const COMMON_NAMESPACE = 'Facebook\PersistentData\\';
34+
const COMMON_INTERFACE = 'Facebook\PersistentData\PersistentDataInterface';
35+
36+
/**
37+
* @param mixed $handler
38+
* @param string $expected
39+
*
40+
* @dataProvider persistentDataHandlerProviders
41+
*/
42+
public function testCreatePersistentDataHandler($handler, $expected)
43+
{
44+
$persistentDataHandler = PersistentDataFactory::createPersistentDataHandler($handler);
45+
46+
$this->assertInstanceOf(self::COMMON_INTERFACE, $persistentDataHandler);
47+
$this->assertInstanceOf($expected, $persistentDataHandler);
48+
}
49+
50+
/**
51+
* @return array
52+
*/
53+
public function persistentDataHandlerProviders()
54+
{
55+
$handlers = [
56+
['memory', self::COMMON_NAMESPACE . 'FacebookMemoryPersistentDataHandler'],
57+
[new FacebookMemoryPersistentDataHandler(), self::COMMON_NAMESPACE . 'FacebookMemoryPersistentDataHandler'],
58+
[new FacebookSessionPersistentDataHandler(false), self::COMMON_NAMESPACE . 'FacebookSessionPersistentDataHandler'],
59+
[null, self::COMMON_INTERFACE],
60+
];
61+
62+
if (session_status() === PHP_SESSION_ACTIVE) {
63+
$handlers[] = ['session', self::COMMON_NAMESPACE . 'FacebookSessionPersistentDataHandler'];
64+
}
65+
66+
return $handlers;
67+
}
68+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
/**
3+
* Copyright 2014 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\PseudoRandomString;
25+
26+
use Facebook\PseudoRandomString\McryptPseudoRandomStringGenerator;
27+
use Facebook\PseudoRandomString\OpenSslPseudoRandomStringGenerator;
28+
use Facebook\PseudoRandomString\PseudoRandomStringGeneratorFactory;
29+
use Facebook\PseudoRandomString\UrandomPseudoRandomStringGenerator;
30+
use PHPUnit_Framework_TestCase;
31+
32+
class PseudoRandomStringFactoryTest extends PHPUnit_Framework_TestCase
33+
{
34+
const COMMON_NAMESPACE = 'Facebook\PseudoRandomString\\';
35+
const COMMON_INTERFACE = 'Facebook\PseudoRandomString\PseudoRandomStringGeneratorInterface';
36+
37+
/**
38+
* @param mixed $handler
39+
* @param string $expected
40+
*
41+
* @dataProvider httpClientsProvider
42+
*/
43+
public function testCreateHttpClient($handler, $expected)
44+
{
45+
$pseudoRandomStringGenerator = PseudoRandomStringGeneratorFactory::createPseudoRandomStringGenerator($handler);
46+
47+
$this->assertInstanceOf(self::COMMON_INTERFACE, $pseudoRandomStringGenerator);
48+
$this->assertInstanceOf($expected, $pseudoRandomStringGenerator);
49+
}
50+
51+
/**
52+
* @return array
53+
*/
54+
public function httpClientsProvider()
55+
{
56+
return [
57+
['mcrypt', self::COMMON_NAMESPACE . 'McryptPseudoRandomStringGenerator'],
58+
['openssl', self::COMMON_NAMESPACE . 'OpenSslPseudoRandomStringGenerator'],
59+
['urandom', self::COMMON_NAMESPACE . 'UrandomPseudoRandomStringGenerator'],
60+
[null, self::COMMON_INTERFACE],
61+
];
62+
}
63+
}

0 commit comments

Comments
 (0)