Completed
Pull Request — master (#30)
by Rudolph
04:05 queued 53s
created

FileStorageTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
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