Completed
Pull Request — master (#135)
by Alexander
03:55
created

SessionTest::testGetAndSet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
cc 1
eloc 3
c 2
b 1
f 0
nc 1
nop 0
dl 0
loc 5
rs 10
1
<?php
2
3
namespace Yiisoft\Yii\Web\Tests\Session;
4
5
use Yiisoft\Yii\Web\Session\Session;
6
use PHPUnit\Framework\TestCase;
7
8
class SessionTest extends TestCase
9
{
10
    /**
11
     * @runInSeparateProcess
12
     */
13
    public function testGetAndSet()
14
    {
15
        $session = new Session();
16
        $session->set('key_get', 'value');
17
        self::assertEquals('value', $session->get('key_get'));
18
    }
19
20
    /**
21
     * @runInSeparateProcess
22
     */
23
    public function testHas()
24
    {
25
        $session = new Session();
26
        $session->set('key_has', 'value');
27
        self::assertTrue($session->has('key_has'));
28
    }
29
30
    /**
31
     * @runInSeparateProcess
32
     */
33
    public function testClose()
34
    {
35
        $session = new Session();
36
        $session->set('key_close', 'value');
37
        $session->close();
38
        self::assertEquals(PHP_SESSION_NONE, session_status());
39
    }
40
41
    /**
42
     * @runInSeparateProcess
43
     */
44
    public function testRegenerateID()
45
    {
46
        $session = new Session();
47
        $session->open();
48
        $id = $session->getId();
49
        $session->regenerateId();
50
        self::assertNotEquals($id, $session->getId());
51
    }
52
53
    /**
54
     * @runInSeparateProcess
55
     */
56
    public function testDiscard()
57
    {
58
        $session = new Session();
59
        $session->set('key_discard', 'value');
60
        $session->discard();
61
        self::assertEmpty($session->get('key_discard'));
62
    }
63
64
    public function testGetName()
65
    {
66
        $session = new Session();
67
        self::assertEquals($session->getName(), session_name());
68
    }
69
70
    /**
71
     * @runInSeparateProcess
72
     */
73
    public function testPull()
74
    {
75
        $session = new Session();
76
        $session->set('key_pull', 'value');
77
        self::assertEquals('value', $session->pull('key_pull'));
78
        self::assertEmpty($session->get('key_pull'));
79
    }
80
81
    /**
82
     * @runInSeparateProcess
83
     */
84
    public function testAll()
85
    {
86
        $session = new Session();
87
        $session->set('key_1', 1);
88
        $session->set('key_2', 2);
89
        self::assertEquals(['key_1' => 1, 'key_2' => 2], $session->all());
90
    }
91
92
    /**
93
     * @runInSeparateProcess
94
     */
95
    public function testClear()
96
    {
97
        $session = new Session();
98
        $session->set('key', 'value');
99
        $session->clear();
100
        self::assertEmpty($session->all());
101
    }
102
103
    /**
104
     * @runInSeparateProcess
105
     */
106
    public function testSetId()
107
    {
108
        $session = new Session();
109
        $session->setId('sessionId');
110
        $session->open();
111
        self::assertEquals(session_id(), $session->getId());
112
    }
113
114
    public function testGetCookieParameters()
115
    {
116
        $session = new Session();
117
        self::assertEquals(session_get_cookie_params(), $session->getCookieParameters());
118
    }
119
120
    /**
121
     * @expectedException \RuntimeException
122
     */
123
    public function testAlreadyStartedException()
124
    {
125
        $session = new Session();
126
        $session->open();
127
        new Session();
128
    }
129
}
130