|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SilverStripe\HybridSessions\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use SilverStripe\Dev\SapphireTest; |
|
6
|
|
|
use SilverStripe\HybridSessions\HybridSession; |
|
7
|
|
|
use SilverStripe\HybridSessions\Store\BaseStore; |
|
8
|
|
|
use SilverStripe\HybridSessions\Tests\Store\TestCookieStore; |
|
9
|
|
|
|
|
10
|
|
|
class HybridSessionTest extends SapphireTest |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @var BaseStore |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $handler; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var HybridSession |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $instance; |
|
21
|
|
|
|
|
22
|
|
|
protected function setUp() |
|
23
|
|
|
{ |
|
24
|
|
|
parent::setUp(); |
|
25
|
|
|
|
|
26
|
|
|
$this->handler = $this->createMock(TestCookieStore::class); |
|
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
$this->instance = new HybridSession(); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function testSetHandlersAlsoSetsKeyToEachHandler() |
|
32
|
|
|
{ |
|
33
|
|
|
$this->instance->setKey('foobar'); |
|
34
|
|
|
$this->handler->expects($this->once())->method('setKey')->with('foobar'); |
|
|
|
|
|
|
35
|
|
|
$this->instance->setHandlers([$this->handler]); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function testOpenDelegatesToAllHandlers() |
|
39
|
|
|
{ |
|
40
|
|
|
$this->handler->expects($this->once())->method('open')->with('foo', 'bar'); |
|
|
|
|
|
|
41
|
|
|
$this->instance->setHandlers([$this->handler]); |
|
42
|
|
|
$this->assertTrue($this->instance->open('foo', 'bar'), 'Method returns true after delegation'); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function testCloseDelegatesToAllHandlers() |
|
46
|
|
|
{ |
|
47
|
|
|
$this->handler->expects($this->once())->method('close'); |
|
|
|
|
|
|
48
|
|
|
$this->instance->setHandlers([$this->handler]); |
|
49
|
|
|
$this->assertTrue($this->instance->close(), 'Method returns true after delegation'); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function testReadReturnsEmptyStringWithNoHandlers() |
|
53
|
|
|
{ |
|
54
|
|
|
$this->handler->expects($this->once())->method('read')->with('foosession')->willReturn(false); |
|
|
|
|
|
|
55
|
|
|
$this->instance->setHandlers([$this->handler]); |
|
56
|
|
|
$this->assertSame('', $this->instance->read('foosession')); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function testReadReturnsHandlerDelegateResult() |
|
60
|
|
|
{ |
|
61
|
|
|
$this->handler->expects($this->once())->method('read')->with('foo.session')->willReturn('success!'); |
|
|
|
|
|
|
62
|
|
|
$this->instance->setHandlers([$this->handler]); |
|
63
|
|
|
$this->assertSame('success!', $this->instance->read('foo.session')); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function testWriteDelegatesToHandlerAndReturnsTrue() |
|
67
|
|
|
{ |
|
68
|
|
|
$this->handler->expects($this->once())->method('write')->with('foo', 'bar')->willReturn(true); |
|
|
|
|
|
|
69
|
|
|
$this->instance->setHandlers([$this->handler]); |
|
70
|
|
|
$this->assertTrue($this->instance->write('foo', 'bar')); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function testWriteReturnsFalseWithNoHandlers() |
|
74
|
|
|
{ |
|
75
|
|
|
$this->assertFalse($this->instance->write('no', 'handlers')); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function testDestroyDelegatesToHandler() |
|
79
|
|
|
{ |
|
80
|
|
|
$this->handler->expects($this->once())->method('destroy')->with('sessid1234'); |
|
|
|
|
|
|
81
|
|
|
$this->instance->setHandlers([$this->handler]); |
|
82
|
|
|
$this->assertTrue($this->instance->destroy('sessid1234'), 'Method returns true after delegation'); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function testGcDelegatesToHandlers() |
|
86
|
|
|
{ |
|
87
|
|
|
$this->handler->expects($this->once())->method('gc')->with(12345); |
|
|
|
|
|
|
88
|
|
|
$this->instance->setHandlers([$this->handler]); |
|
89
|
|
|
$this->instance->gc(12345); |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..