Passed
Pull Request — main (#33)
by Sílvio
03:05
created

SecurityFeatureTest::testEncryptionFeature()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 11
rs 10
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
        $this->cache->setDriver()->useFileDriver();
20
    }
21
22
    protected function tearDown(): void
23
    {
24
        $this->cache->flushCache();
25
    }
26
27
    public function testCompressionFeature()
28
    {
29
        $this->cache->useCompression();
30
        $data = ['foo' => 'bar'];
31
32
        $this->cache->putCache('compression_key', $data);
33
        $this->assertTrue($this->cache->isSuccess());
34
35
        $cached = $this->cache->getCache('compression_key');
36
        $this->assertEquals($data, $cached);
37
    }
38
39
    public function testEncryptionFeature()
40
    {
41
        $this->cache->useEncryption('secret');
42
        $data = ['foo' => 'bar'];
43
44
        $this->cache->putCache('encryption_key', $data);
45
        $this->assertTrue($this->cache->isSuccess());
46
47
        $cached = $this->cache->getCache('encryption_key');
48
49
        $this->assertEquals($data, $cached);
50
    }
51
52
    public function testCompressionAndEncryptionTogether()
53
    {
54
        $this->cache->useCompression();
55
        $this->cache->useEncryption('secret');
56
        $data = ['foo' => 'bar'];
57
58
        $this->cache->putCache('secure_key', $data);
59
        $this->assertTrue($this->cache->isSuccess());
60
61
        $cached = $this->cache->getCache('secure_key');
62
        $this->assertEquals($data, $cached);
63
    }
64
}
65