forked from absolute-quantum/DoctrineEncryptBundle
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDefuseEncryptorTest.php
More file actions
41 lines (32 loc) · 1.21 KB
/
Copy pathDefuseEncryptorTest.php
File metadata and controls
41 lines (32 loc) · 1.21 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
<?php
namespace Ambta\DoctrineEncryptBundle\Tests\Unit\Encryptors;
use Ambta\DoctrineEncryptBundle\Encryptors\DefuseEncryptor;
use PHPUnit\Framework\TestCase;
class DefuseEncryptorTest extends TestCase
{
private const DATA = 'foobar';
public function testEncrypt(): void
{
$keyfile = __DIR__.'/fixtures/defuse.key';
$key = file_get_contents($keyfile);
$defuse = new DefuseEncryptor($keyfile);
$encrypted = $defuse->encrypt(self::DATA);
$this->assertNotSame(self::DATA, $encrypted);
$decrypted = $defuse->decrypt($encrypted);
$this->assertSame(self::DATA, $decrypted);
$newkey = file_get_contents($keyfile);
$this->assertSame($key, $newkey, 'The key must not be modified');
}
public function testGenerateKey(): void
{
$keyfile = sys_get_temp_dir().'/defuse-'.md5(time());
if (file_exists($keyfile)) {
unlink($keyfile);
}
$defuse = new DefuseEncryptor($keyfile);
$defuse->encrypt(self::DATA);
$this->assertFileExists($keyfile);
$this->assertNotEmpty(file_get_contents($keyfile), 'A key should have been created and saved to the file');
unlink($keyfile);
}
}