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
|
|
|
} |
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.