Repository navigation
Expand file tree
/
Copy pathEncryptionTest.php
More file actions
64 lines (49 loc) · 2.07 KB
/
Copy pathEncryptionTest.php
File metadata and controls
64 lines (49 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
/** @noinspection ForgottenDebugOutputInspection */
declare(strict_types=1);
namespace Rancoud\Session\Test;
use PHPUnit\Framework\TestCase;
use Rancoud\Session\SessionException;
/**
* Class EncryptedTest.
*/
class EncryptionTest extends TestCase
{
public function testDefaultEncryption(): void
{
$encryptionTrait = $this->getObjectForTrait('Rancoud\Session\Encryption');
$dataToEncrypt = 'this is something to encrypt';
$encryptionTrait->setKey('my key');
$encryptedData = $encryptionTrait->encrypt($dataToEncrypt);
$finalData = $encryptionTrait->decrypt($encryptedData);
static::assertEquals($dataToEncrypt, $finalData);
}
public function testAllEncryptionMethods(): void
{
$encryptionTrait = $this->getObjectForTrait('Rancoud\Session\Encryption');
$dataToEncrypt = 'this is something to encrypt';
$encryptionTrait->setKey('my key');
$methods = $encryptionTrait->getAvailableMethods();
foreach ($methods as $method) {
$encryptionTrait->setMethod($method);
$encryptedData = $encryptionTrait->encrypt($dataToEncrypt);
$finalData = $encryptionTrait->decrypt($encryptedData);
static::assertEquals($dataToEncrypt, $finalData, $method . ' fail!');
}
}
public function testExceptionMethod(): void
{
$this->expectException(SessionException::class);
$this->expectExceptionMessage('Method unknowed: method');
$encryptionTrait = $this->getObjectForTrait('Rancoud\Session\Encryption');
$encryptionTrait->setMethod('method');
}
public function testExceptionEmptyKey(): void
{
$this->expectException(SessionException::class);
$this->expectExceptionMessage('Key has to be a non-empty string');
$encryptionTrait = $this->getObjectForTrait('Rancoud\Session\Encryption');
$dataToEncrypt = 'this is something to encrypt';
$encryptionTrait->encrypt($dataToEncrypt);
}
}