1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types = 1); |
4
|
|
|
|
5
|
|
|
namespace PSR7SessionsTest\Storage\Adapter; |
6
|
|
|
|
7
|
|
|
use org\bovigo\vfs\vfsStream; |
8
|
|
|
use org\bovigo\vfs\vfsStreamDirectory; |
9
|
|
|
use PHPUnit_Framework_TestCase; |
10
|
|
|
use PSR7Sessions\Storage\Adapter\FileStorage; |
11
|
|
|
use PSR7Sessions\Storage\Session\StorableSession; |
12
|
|
|
use PSR7Sessions\Storage\Session\StorableSessionInterface; |
13
|
|
|
use PSR7Sessions\Storageless\Session\DefaultSessionData; |
14
|
|
|
|
15
|
|
|
class FileStorageTest extends PHPUnit_Framework_TestCase |
16
|
|
|
{ |
17
|
|
|
/** @var vfsStreamDirectory */ |
18
|
|
|
private $fileSystem; |
19
|
|
|
/** @var FileStorage */ |
20
|
|
|
private $storage; |
21
|
|
|
|
22
|
|
|
public function setUp() |
23
|
|
|
{ |
24
|
|
|
$this->fileSystem = vfsStream::setup(); |
25
|
|
|
$this->storage = new FileStorage($this->fileSystem->url()); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function testSaveNewSession() |
29
|
|
|
{ |
30
|
|
|
$session = $this->createSession(); |
31
|
|
|
$session->set('test', 'foo'); |
32
|
|
|
|
33
|
|
|
$this->storage->save($session); |
34
|
|
|
|
35
|
|
|
$loadedSession = $this->storage->load($session->getId()); |
36
|
|
|
$this->assertEquals($session->get('test'), $loadedSession->get('test')); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testDestroy() |
40
|
|
|
{ |
41
|
|
|
$session = $this->createSession(); |
42
|
|
|
$session->set('foo', 'bar'); |
43
|
|
|
$this->storage->save($session); |
44
|
|
|
|
45
|
|
|
$this->storage->destroy($session->getId()); |
46
|
|
|
|
47
|
|
|
$loaded = $this->storage->load($session->getId()); |
48
|
|
|
$this->assertFalse($loaded->has('foo')); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
private function createSession():StorableSessionInterface |
52
|
|
|
{ |
53
|
|
|
$innerSession = DefaultSessionData::newEmptySession(); |
54
|
|
|
return new StorableSession($innerSession, $this->storage); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|