1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright 2017 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
|
|
|
namespace Facebook\Tests\PersistentData; |
24
|
|
|
|
25
|
|
|
use Facebook\PersistentData\InMemoryPersistentDataHandler; |
26
|
|
|
use Facebook\PersistentData\SessionPersistentDataHandler; |
27
|
|
|
use Facebook\PersistentData\PersistentDataFactory; |
28
|
|
|
use Facebook\PersistentData\PersistentDataInterface; |
29
|
|
|
use PHPUnit\Framework\TestCase; |
30
|
|
|
|
31
|
|
|
class PersistentDataFactoryTest extends TestCase |
32
|
|
|
{ |
33
|
|
|
const COMMON_NAMESPACE = 'Facebook\PersistentData\\'; |
34
|
|
|
const COMMON_INTERFACE = PersistentDataInterface::class; |
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 . 'InMemoryPersistentDataHandler'], |
57
|
|
|
[new InMemoryPersistentDataHandler(), self::COMMON_NAMESPACE . 'InMemoryPersistentDataHandler'], |
58
|
|
|
[new SessionPersistentDataHandler(false), self::COMMON_NAMESPACE . 'SessionPersistentDataHandler'], |
59
|
|
|
[null, self::COMMON_INTERFACE], |
60
|
|
|
]; |
61
|
|
|
|
62
|
|
|
if (session_status() === PHP_SESSION_ACTIVE) { |
63
|
|
|
$handlers[] = ['session', self::COMMON_NAMESPACE . 'SessionPersistentDataHandler']; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
return $handlers; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|