SessionTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 58
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 12 2
A testSessionAccessorMuttator() 0 16 1
A testSessionGenerate() 0 11 1
1
<?php
2
/**
3
 * SessionWare (https://github.com/juliangut/sessionware)
4
 * PSR7 session management middleware
5
 *
6
 * @license BSD-3-Clause
7
 * @author Julián Gutiérrez <[email protected]>
8
 */
9
10
namespace Jgut\Middleware\Sessionware\Tests;
11
12
use Jgut\Middleware\Session;
13
14
/**
15
 * PHP session helper test class.
16
 */
17
class SessionTest extends \PHPUnit_Framework_TestCase
18
{
19
    /**
20
     * @var Session
21
     */
22
    protected $session;
23
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function setUp()
28
    {
29
        if (session_status() !== PHP_SESSION_ACTIVE) {
30
            // Set a high probability to launch garbage collector
31
            ini_set('session.gc_probability', 1);
32
            ini_set('session.gc_divisor', 4);
33
34
            session_start();
35
        }
36
37
        $this->session = new Session;
38
    }
39
40
    /**
41
     * @runInSeparateProcess
42
     */
43
    public function testSessionAccessorMuttator()
44
    {
45
        self::assertFalse($this->session->has('sessionKey'));
46
47
        $this->session->set('sessionKeyOne', 'sessionValueOne');
48
        $this->session->set('sessionKeyTwo', 'sessionValueTwo');
49
        self::assertTrue($this->session->has('sessionKeyOne'));
50
        self::assertEquals('sessionValueOne', $this->session->get('sessionKeyOne'));
51
52
        $this->session->remove('sessionKeyOne');
53
        self::assertFalse($this->session->has('sessionKeyOne'));
54
        self::assertEquals('noValue', $this->session->get('sessionKeyOne', 'noValue'));
55
56
        $this->session->clear();
57
        self::assertFalse($this->session->has('sessionKeyTwo'));
58
    }
59
60
    /**
61
     * @runInSeparateProcess
62
     */
63
    public function testSessionGenerate()
64
    {
65
        $sessionId = session_id();
66
67
        $this->session->set('saveKey', 'safeValue');
68
        $this->session->regenerate();
69
70
        self::assertNotEquals($sessionId, session_id());
71
        self::assertTrue($this->session->has('saveKey'));
72
        self::assertEquals('safeValue', $this->session->get('saveKey'));
73
    }
74
}
75