-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFactoryTest.php
More file actions
69 lines (57 loc) · 2.3 KB
/
FactoryTest.php
File metadata and controls
69 lines (57 loc) · 2.3 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
65
66
67
68
69
<?php declare(strict_types=1);
namespace Tests\FileEncryptor;
use PHPUnit\Framework\TestCase;
/**
* 测试 php-file-encryptor\FileEncryptor\Factory
*
* @author fdipzone
*/
final class FactoryTest extends TestCase
{
/**
* @covers \FileEncryptor\Factory::make
*/
public function testMake()
{
$encrypt_key = '123456';
$xor_encryptor = \FileEncryptor\Factory::make(\FileEncryptor\Type::XOR, $encrypt_key);
$this->assertEquals('FileEncryptor\XorEncryptor', get_class($xor_encryptor));
$aes_encryptor = \FileEncryptor\Factory::make(\FileEncryptor\Type::AES, $encrypt_key);
$this->assertEquals('FileEncryptor\AesEncryptor', get_class($aes_encryptor));
$des_encryptor = \FileEncryptor\Factory::make(\FileEncryptor\Type::DES, $encrypt_key);
$this->assertEquals('FileEncryptor\DesEncryptor', get_class($des_encryptor));
}
/**
* @covers \FileEncryptor\Factory::make
*/
public function testMakeException()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('file encryptor factory: type not_exists_type not exists');
$type = 'not_exists_type';
$encrypt_key = '123456';
\FileEncryptor\Factory::make($type, $encrypt_key);
}
/**
* @covers \FileEncryptor\Factory::getEncryptorClass
*/
public function testGetEncryptorClass()
{
$xor_encryptor_class = \FileEncryptor\Factory::getEncryptorClass(\FileEncryptor\Type::XOR);
$this->assertEquals('\FileEncryptor\XorEncryptor', $xor_encryptor_class);
$aes_encryptor_class = \FileEncryptor\Factory::getEncryptorClass(\FileEncryptor\Type::AES);
$this->assertEquals('\FileEncryptor\AesEncryptor', $aes_encryptor_class);
$des_encryptor_class = \FileEncryptor\Factory::getEncryptorClass(\FileEncryptor\Type::DES);
$this->assertEquals('\FileEncryptor\DesEncryptor', $des_encryptor_class);
}
/**
* @covers \FileEncryptor\Factory::getEncryptorClass
*/
public function testGetEncryptorClassException()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('file encryptor factory: type not_exists_type not exists');
$type = 'not_exists_type';
\FileEncryptor\Factory::getEncryptorClass($type);
}
}