Completed
Push — master ( 018230...7fadd3 )
by Arthur
01:58
created

CoossionsTest::testSetEncryption()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 10
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 8
nc 1
nop 0
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()
0 ignored issues
show
Unused Code Comprehensibility introduced by
51% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
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()
0 ignored issues
show
Unused Code Comprehensibility introduced by
40% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
64
//    {
65
//
66
//    }
67
}