CoossionsTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 52
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
A testSetEncryption() 0 10 1
A testSessionHandlerMethods() 0 10 1
1
<?php
2
namespace coossionstest;
3
4
use coossions\base\Coossions;
5
use coossions\CoossionsHandler;
6
use coossions\crypt\Encryptor;
7
use PHPUnit\Framework\TestCase;
8
9
/**
10
 * Class EncryptorTest
11
 * @package coossionstest
12
 *
13
 * @property Coossions coossions
14
 * @property Encryptor encryptor
15
 */
16
final class CoossionsTest extends TestCase
17
{
18
    private $coossions = null;
19
    private $sid = 'sid';
20
    private $secret = 'secret';
21
22
    public function setUp()
23
    {
24
        $this->coossions = new Coossions($this->secret);
25
        $this->encryptor = new Encryptor($this->secret);
26
        $this->sid = md5($this->sid);
27
    }
28
29
    public function testSetEncryption()
30
    {
31
        $sha512 = 'sha512';
32
        $aes128 = 'aes-256-cbc';
33
        $this->encryptor->setDigestAlgo($sha512); // defaults to sha256
34
        $this->encryptor->setCipherAlgo($aes128); // defaults to aes-256-ctr
35
        $this->coossions->setEncryption($this->encryptor);
36
        $this->assertEquals($this->coossions->getDigestAlgo(), $sha512);
37
        $this->assertEquals($this->coossions->getCipherAlgo(), $aes128);
38
    }
39
40
    /**
41
     * We must run this test in separate process coz of setcookie headers
42
     * @runInSeparateProcess
43
     */
44
    public function testSessionHandlerMethods()
45
    {
46
        $data = 'foo bar baz';
47
        $this->assertTrue($this->coossions->open('', $this->sid));
48
        $this->assertTrue($this->coossions->write($this->sid, $data));
49
        $this->assertEquals('', $this->coossions->read($this->sid));
50
        $this->assertTrue($this->coossions->close());
51
        $this->assertTrue($this->coossions->destroy($this->sid));
52
        $this->assertTrue($this->coossions->gc(1000));
53
    }
54
55
//    public function testCoossionsHandler()
56
//    {
57
//        $coossions = new CoossionsHandler($this->secret); // any secret word
58
//        $coossions->startSession();
59
//        // testing that session_starts normally and have defined an empty global array
60
//        $this->assertArraySubset([], $_SESSION);
61
//    }
62
63
//    public function testExceptions()
64
//    {
65
//
66
//    }
67
}