Passed
Push — master ( 6d4a3c...d9bd74 )
by Kashyap
01:15
created

IPFuscatorTest::testCanBeValidRandomHexPad()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 4
c 1
b 0
f 1
dl 0
loc 6
rs 10
cc 3
nc 3
nop 0
1
<?php
2
3
/**
4
 *
5
 * Part of the IPFuscator package.
6
 * Author: Kashyap Merai <[email protected]>
7
 *
8
 */
9
10
use kamerk22\IPFuscator\Exception\InvalidArgument;
11
use kamerk22\IPFuscator\IPFuscator;
12
use PHPUnit\Framework\TestCase;
13
14
class IPFuscatorTest extends TestCase
15
{
16
    public $ip = '127.0.0.1';
17
18
    public function testCanBeUsedWithValidIp(): void
19
    {
20
        $this->assertNotEmpty(IPFuscator::getDecimal($this->ip));
21
    }
22
23
    public function testCanBeUsedWithInvalidIp(): void
24
    {
25
        $this->expectException(InvalidArgument::class);
26
        IPFuscator::getDecimal('in.va.lid.ip');
27
    }
28
29
    public function testCanBeValidDecimal(): void
30
    {
31
        $this->assertEquals(
32
            '2130706433',
33
            IPFuscator::getDecimal($this->ip)
34
        );
35
    }
36
37
    public function testCanBeValidHexadecimal(): void
38
    {
39
        $this->assertEquals(
40
            '0x7f000001',
41
            IPFuscator::getHexadecimal($this->ip)
42
        );
43
    }
44
45
    public function testCanBeValidOctal(): void
46
    {
47
        $this->assertEquals(
48
            '017700000001',
49
            IPFuscator::getOctal($this->ip)
50
        );
51
    }
52
53
    public function testCanBeValidFullHex(): void
54
    {
55
        $this->assertEquals(
56
            '0x7f.0x0.0x0.0x1',
57
            IPFuscator::getFullHex($this->ip)
58
        );
59
    }
60
61
    public function testCanBeValidFullOct(): void
62
    {
63
        $this->assertEquals(
64
            '0177.00.00.01',
65
            IPFuscator::getFullOct($this->ip)
66
        );
67
    }
68
69
    public function testCanBeValidRandomHexPad(): void
70
    {
71
        try {
72
            $this->assertNotEmpty(IPFuscator::getRandomHexPad($this->ip));
73
        } catch (InvalidArgument $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
74
        } catch (Exception $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
75
        }
76
    }
77
78
    public function testCanBeValidRandomOctPad(): void
79
    {
80
        try {
81
            $this->assertNotEmpty(IPFuscator::getRandomOctPad($this->ip));
82
        } catch (InvalidArgument $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
83
        } catch (Exception $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
84
        }
85
    }
86
87
    public function testCanBeValidRandomBase(): void
88
    {
89
        try {
90
            $this->assertNotEmpty(IPFuscator::getRandomBase($this->ip));
91
        } catch (InvalidArgument $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
92
        } catch (Exception $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
93
        }
94
    }
95
96
    public function testCanBeValidRandomBaseWithPad(): void
97
    {
98
        try {
99
            $this->assertNotEmpty(IPFuscator::getRandomBaseWithRandomPad($this->ip));
100
        } catch (InvalidArgument $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
101
        } catch (Exception $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
102
        }
103
    }
104
}