Passed
Push — master ( b0f0bc...e7fcd7 )
by ma
02:00
created

EncryptionTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 22
c 1
b 0
f 0
dl 0
loc 37
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testAuthcodeEncode() 0 6 1
A testAuthcodeWithoutExpiry() 0 7 1
A testAuthcodeDecode() 0 7 1
A testAuthcodeWithExpiry() 0 9 1
1
<?php
2
3
use PHPUnit\Framework\TestCase;
4
use tinymeng\tools\Encryption;
5
6
class EncryptionTest extends TestCase
7
{
8
    public function testAuthcodeEncode()
9
    {
10
        $originalString = 'Hello, World!';
11
        $key = 'tinymeng';
12
        $encodedString = Encryption::authcode($originalString, 'encode', $key);
13
        $this->assertNotEquals($originalString, $encodedString);
14
    }
15
16
    public function testAuthcodeDecode()
17
    {
18
        $originalString = 'Hello, World!';
19
        $key = 'tinymeng';
20
        $encodedString = Encryption::authcode($originalString, 'encode', $key);
21
        $decodedString = Encryption::authcode($encodedString, 'decode', $key);
22
        $this->assertEquals($originalString, $decodedString);
23
    }
24
25
    public function testAuthcodeWithExpiry()
26
    {
27
        $originalString = 'Hello, World!';
28
        $key = 'tinymeng';
29
        $expiry = 10; // 10 seconds
30
        $encodedString = Encryption::authcode($originalString, 'encode', $key, $expiry);
31
        sleep(11); // Wait for the encoded string to expire
32
        $decodedString = Encryption::authcode($encodedString, 'decode', $key);
33
        $this->assertEquals('', $decodedString);
34
    }
35
36
    public function testAuthcodeWithoutExpiry()
37
    {
38
        $originalString = 'Hello, World!';
39
        $key = 'tinymeng';
40
        $encodedString = Encryption::authcode($originalString, 'encode', $key);
41
        $decodedString = Encryption::authcode($encodedString, 'decode', $key);
42
        $this->assertEquals($originalString, $decodedString);
43
    }
44
}
45