1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use PHPUnit\Framework\TestCase; |
4
|
|
|
use Silviooosilva\CacheerPhp\Cacheer; |
5
|
|
|
|
6
|
|
|
class SecurityFeatureTest extends TestCase |
7
|
|
|
{ |
8
|
|
|
private $cache; |
9
|
|
|
private $cacheDir; |
10
|
|
|
|
11
|
|
|
protected function setUp(): void |
12
|
|
|
{ |
13
|
|
|
$this->cacheDir = __DIR__ . '/cache'; |
14
|
|
|
if (!is_dir($this->cacheDir)) { |
15
|
|
|
mkdir($this->cacheDir, 0755, true); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
$this->cache = new Cacheer(['cacheDir' => $this->cacheDir]); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
protected function tearDown(): void |
22
|
|
|
{ |
23
|
|
|
$this->cache->flushCache(); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function testCompressionFeature() |
27
|
|
|
{ |
28
|
|
|
$this->cache->useCompression(); |
29
|
|
|
$data = ['foo' => 'bar']; |
30
|
|
|
|
31
|
|
|
$this->cache->putCache('compression_key', $data); |
32
|
|
|
$this->assertTrue($this->cache->isSuccess()); |
33
|
|
|
|
34
|
|
|
$cached = $this->cache->getCache('compression_key'); |
35
|
|
|
$this->assertEquals($data, $cached); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testEncryptionFeature() |
39
|
|
|
{ |
40
|
|
|
$this->cache->useEncryption('secret'); |
41
|
|
|
$data = ['foo' => 'bar']; |
42
|
|
|
|
43
|
|
|
$this->cache->putCache('encryption_key', $data); |
44
|
|
|
$this->assertTrue($this->cache->isSuccess()); |
45
|
|
|
|
46
|
|
|
$cached = $this->cache->getCache('encryption_key'); |
47
|
|
|
$this->assertEquals($data, $cached); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function testCompressionAndEncryptionTogether() |
51
|
|
|
{ |
52
|
|
|
$this->cache->useCompression(); |
53
|
|
|
$this->cache->useEncryption('secret'); |
54
|
|
|
$data = ['foo' => 'bar']; |
55
|
|
|
|
56
|
|
|
$this->cache->putCache('secure_key', $data); |
57
|
|
|
$this->assertTrue($this->cache->isSuccess()); |
58
|
|
|
|
59
|
|
|
$cached = $this->cache->getCache('secure_key'); |
60
|
|
|
$this->assertEquals($data, $cached); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|