1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OAuthTest\Unit\Common\Storage; |
4
|
|
|
|
5
|
|
|
use OAuth\Common\Storage\Memory; |
6
|
|
|
|
7
|
|
|
class MemoryTest extends \PHPUnit_Framework_TestCase |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* @covers OAuth\Common\Storage\Memory::__construct |
11
|
|
|
*/ |
12
|
|
|
public function testConstructCorrectInterface() |
13
|
|
|
{ |
14
|
|
|
$storage = new Memory(); |
15
|
|
|
|
16
|
|
|
$this->assertInstanceOf('\\OAuth\\Common\\Storage\\TokenStorageInterface', $storage); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @covers OAuth\Common\Storage\Memory::__construct |
21
|
|
|
* @covers OAuth\Common\Storage\Memory::storeAccessToken |
22
|
|
|
*/ |
23
|
|
|
public function testStoreAccessToken() |
24
|
|
|
{ |
25
|
|
|
$storage = new Memory(); |
26
|
|
|
|
27
|
|
|
$this->assertInstanceOf( |
28
|
|
|
'\\OAuth\\Common\\Storage\\Memory', |
29
|
|
|
$storage->storeAccessToken('foo', $this->getMock('\\OAuth\\Common\\Token\\TokenInterface')) |
30
|
|
|
); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @covers OAuth\Common\Storage\Memory::__construct |
35
|
|
|
* @covers OAuth\Common\Storage\Memory::storeAccessToken |
36
|
|
|
* @covers OAuth\Common\Storage\Memory::retrieveAccessToken |
37
|
|
|
* @covers OAuth\Common\Storage\Memory::hasAccessToken |
38
|
|
|
*/ |
39
|
|
|
public function testRetrieveAccessTokenValid() |
40
|
|
|
{ |
41
|
|
|
$storage = new Memory(); |
42
|
|
|
|
43
|
|
|
$storage->storeAccessToken('foo', $this->getMock('\\OAuth\\Common\\Token\\TokenInterface')); |
44
|
|
|
|
45
|
|
|
$this->assertInstanceOf('\\OAuth\\Common\\Token\\TokenInterface', $storage->retrieveAccessToken('foo')); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @covers OAuth\Common\Storage\Memory::__construct |
50
|
|
|
* @covers OAuth\Common\Storage\Memory::retrieveAccessToken |
51
|
|
|
* @covers OAuth\Common\Storage\Memory::hasAccessToken |
52
|
|
|
*/ |
53
|
|
|
public function testRetrieveAccessTokenThrowsExceptionWhenTokenIsNotFound() |
54
|
|
|
{ |
55
|
|
|
$this->setExpectedException('\\OAuth\\Common\\Storage\\Exception\\TokenNotFoundException'); |
56
|
|
|
|
57
|
|
|
$storage = new Memory(); |
58
|
|
|
|
59
|
|
|
$storage->retrieveAccessToken('foo'); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @covers OAuth\Common\Storage\Memory::__construct |
64
|
|
|
* @covers OAuth\Common\Storage\Memory::storeAccessToken |
65
|
|
|
* @covers OAuth\Common\Storage\Memory::hasAccessToken |
66
|
|
|
*/ |
67
|
|
|
public function testHasAccessTokenTrue() |
68
|
|
|
{ |
69
|
|
|
$storage = new Memory(); |
70
|
|
|
|
71
|
|
|
$storage->storeAccessToken('foo', $this->getMock('\\OAuth\\Common\\Token\\TokenInterface')); |
72
|
|
|
|
73
|
|
|
$this->assertTrue($storage->hasAccessToken('foo')); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @covers OAuth\Common\Storage\Memory::__construct |
78
|
|
|
* @covers OAuth\Common\Storage\Memory::hasAccessToken |
79
|
|
|
*/ |
80
|
|
|
public function testHasAccessTokenFalse() |
81
|
|
|
{ |
82
|
|
|
$storage = new Memory(); |
83
|
|
|
|
84
|
|
|
$this->assertFalse($storage->hasAccessToken('foo')); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @covers OAuth\Common\Storage\Memory::__construct |
89
|
|
|
* @covers OAuth\Common\Storage\Memory::clearToken |
90
|
|
|
*/ |
91
|
|
|
public function testClearTokenIsNotSet() |
92
|
|
|
{ |
93
|
|
|
$storage = new Memory(); |
94
|
|
|
|
95
|
|
|
$this->assertInstanceOf('\\OAuth\\Common\\Storage\\Memory', $storage->clearToken('foo')); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @covers OAuth\Common\Storage\Memory::__construct |
100
|
|
|
* @covers OAuth\Common\Storage\Memory::storeAccessToken |
101
|
|
|
* @covers OAuth\Common\Storage\Memory::clearToken |
102
|
|
|
*/ |
103
|
|
|
public function testClearTokenSet() |
104
|
|
|
{ |
105
|
|
|
$storage = new Memory(); |
106
|
|
|
|
107
|
|
|
$storage->storeAccessToken('foo', $this->getMock('\\OAuth\\Common\\Token\\TokenInterface')); |
108
|
|
|
|
109
|
|
|
$this->assertTrue($storage->hasAccessToken('foo')); |
110
|
|
|
$this->assertInstanceOf('\\OAuth\\Common\\Storage\\Memory', $storage->clearToken('foo')); |
111
|
|
|
$this->assertFalse($storage->hasAccessToken('foo')); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @covers OAuth\Common\Storage\Memory::__construct |
116
|
|
|
* @covers OAuth\Common\Storage\Memory::storeAccessToken |
117
|
|
|
* @covers OAuth\Common\Storage\Memory::clearAllTokens |
118
|
|
|
*/ |
119
|
|
|
public function testClearAllTokens() |
120
|
|
|
{ |
121
|
|
|
$storage = new Memory(); |
122
|
|
|
|
123
|
|
|
$storage->storeAccessToken('foo', $this->getMock('\\OAuth\\Common\\Token\\TokenInterface')); |
124
|
|
|
$storage->storeAccessToken('bar', $this->getMock('\\OAuth\\Common\\Token\\TokenInterface')); |
125
|
|
|
|
126
|
|
|
$this->assertTrue($storage->hasAccessToken('foo')); |
127
|
|
|
$this->assertTrue($storage->hasAccessToken('bar')); |
128
|
|
|
$this->assertInstanceOf('\\OAuth\\Common\\Storage\\Memory', $storage->clearAllTokens()); |
129
|
|
|
$this->assertFalse($storage->hasAccessToken('foo')); |
130
|
|
|
$this->assertFalse($storage->hasAccessToken('bar')); |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|