Completed
Pull Request — master (#13)
by
unknown
24:06 queued 09:01
created

testGetBlockSeparator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
declare(strict_types=1);
3
4
use \PHPUnit\Framework\TestCase;
5
use \hiqdev\yii2\mfa\base\RecoveryCodeCollection;
6
7
class RecoveryCodeCollectionTest extends TestCase
8
{
9
10
    private $recovery;
11
12
    public function setUp(): void
13
    {
14
        $this->recovery = new RecoveryCodeCollection();
15
    }
16
17
    public function testGetCount(): void
18
    {
19
       $this->assertEquals(10, $this->recovery->getCount());
20
    }
21
22
    public function testSetCount(): void
23
    {
24
        $count = 5;
25
        $this->recovery->setCount($count);
26
        $this->assertEquals($count, $this->recovery->getCount());
27
    }
28
29
    public function testGetBlocks(): void
30
    {
31
        $this->assertEquals(4, $this->recovery->getBlocks());
32
    }
33
34
    public function testSetBlocks(): void
35
    {
36
        $count = 5;
37
        $this->recovery->setBlocks($count);
38
        $this->assertEquals($count, $this->recovery->getBlocks());
39
    }
40
41
    public function testGetBlockLength(): void
42
    {
43
        $this->assertEquals(3, $this->recovery->getBlockLength());
44
    }
45
46
    public function testSetBlockLength(): void
47
    {
48
        $count = 5;
49
        $this->recovery->setBlockLength($count);
50
        $this->assertEquals($count, $this->recovery->getBlockLength());
51
    }
52
53
    public function testGetBlockSeparator(): void
54
    {
55
        $this->assertEquals('-', $this->recovery->getBlockSeparator());
56
    }
57
58
    public function testSetBlockSeparator(): void
59
    {
60
        $sep = '.';
61
        $this->recovery->setBlockSeparator($sep);
62
        $this->assertEquals($sep, $this->recovery->getBlockSeparator());
63
    }
64
65
    public function testGenerate(): void
66
    {
67
        // number of generated codes is correct?
68
        $codes = $this->recovery->generate()->getCodes();
69
        $this->assertEquals($this->recovery->getCount(), count($codes));
70
71
        // number of code blocks is correct?
72
        $firstCode = $codes[0];
73
        $codeBlocks = explode($this->recovery->getBlockSeparator(), $firstCode);
74
        $this->assertEquals($this->recovery->getBlocks(), count($codeBlocks));
75
76
        // length of one code block is correct?
77
        $firstBlock = $codeBlocks[0];
78
        $this->assertEquals($this->recovery->getBlockLength() * 2, strlen($firstBlock));
79
    }
80
81
82
83
}