-
Notifications
You must be signed in to change notification settings - Fork 95
Expand file tree
/
Copy pathSessionStorageTest.php
More file actions
79 lines (65 loc) · 1.88 KB
/
SessionStorageTest.php
File metadata and controls
79 lines (65 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
namespace Happyr\LinkedIn\Storage;
use Mockery as m;
/**
* Class SessionStorageTest.
*
* @author Tobias Nyholm
*/
class SessionStorageTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \Happyr\LinkedIn\Storage\SessionStorage storage
*/
protected $storage;
protected $prefix = 'linkedIn_';
public function setUp()
{
$this->storage = new SessionStorage();
}
public function testSet()
{
$this->storage->set('code', 'foobar');
$this->assertEquals($_SESSION[$this->prefix.'code'], serialize('foobar'));
}
/**
* @expectedException \Happyr\LinkedIn\Exception\InvalidArgumentException
*/
public function testSetFail()
{
$this->storage->set('foobar', 'baz');
}
public function testGet()
{
unset($_SESSION[$this->prefix.'state']);
$result = $this->storage->get('state');
$this->assertNull($result);
$_SESSION[$this->prefix.'code'] = serialize('foobar');
$result = $this->storage->get('code');
$this->assertEquals('foobar', $result);
}
public function testClear()
{
$_SESSION[$this->prefix.'code'] = 'foobar';
$this->storage->clear('code');
$this->assertFalse(isset($_SESSION[$this->prefix.'code']));
}
/**
* @expectedException \Happyr\LinkedIn\Exception\InvalidArgumentException
*/
public function testClearFail()
{
$this->storage->clear('foobar');
}
public function testClearAll()
{
$validKeys = SessionStorage::$validKeys;
$storage = m::mock('Happyr\LinkedIn\Storage\SessionStorage[clear]')
->shouldReceive('clear')->times(count($validKeys))
->with(m::on(function ($arg) use ($validKeys) {
return in_array($arg, $validKeys);
}))
->getMock();
$storage->clearAll();
}
}