Passed
Push — master ( f100d5...fd19b3 )
by Kashyap
01:20
created

IPFuscatorTest::testCanBeValidRandomHexPad()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
eloc 1
c 2
b 1
f 1
dl 0
loc 3
rs 10
cc 1
nc 1
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
    /**
19
     * testCanBeUsedWithValidIp
20
     * @throws InvalidArgument
21
     */
22
    public function testCanBeUsedWithValidIp(): void
23
    {
24
        $this->assertNotEmpty(IPFuscator::getDecimal($this->ip));
25
    }
26
27
    /**
28
     * testCanBeUsedWithInvalidIp
29
     * @throws InvalidArgument
30
     */
31
    public function testCanBeUsedWithInvalidIp(): void
32
    {
33
        $this->expectException(InvalidArgument::class);
34
        IPFuscator::getDecimal('in.va.lid.ip');
35
    }
36
37
    /**
38
     * testCanBeValidDecimal
39
     * @throws InvalidArgument
40
     */
41
    public function testCanBeValidDecimal(): void
42
    {
43
        $this->assertEquals(
44
            '2130706433',
45
            IPFuscator::getDecimal($this->ip)
46
        );
47
    }
48
49
    /**
50
     * testCanBeValidHexadecimal
51
     * @throws InvalidArgument
52
     */
53
    public function testCanBeValidHexadecimal(): void
54
    {
55
        $this->assertEquals(
56
            '0x7f000001',
57
            IPFuscator::getHexadecimal($this->ip)
58
        );
59
    }
60
61
    /**
62
     * testCanBeValidOctal
63
     * @throws InvalidArgument
64
     */
65
    public function testCanBeValidOctal(): void
66
    {
67
        $this->assertEquals(
68
            '017700000001',
69
            IPFuscator::getOctal($this->ip)
70
        );
71
    }
72
73
    /**
74
     * testCanBeValidFullHex
75
     * @throws InvalidArgument
76
     */
77
    public function testCanBeValidFullHex(): void
78
    {
79
        $this->assertEquals(
80
            '0x7f.0x0.0x0.0x1',
81
            IPFuscator::getFullHex($this->ip)
82
        );
83
    }
84
85
    /**
86
     * testCanBeValidFullOct
87
     * @throws InvalidArgument
88
     */
89
    public function testCanBeValidFullOct(): void
90
    {
91
        $this->assertEquals(
92
            '0177.00.00.01',
93
            IPFuscator::getFullOct($this->ip)
94
        );
95
    }
96
97
98
    /**
99
     * testCanBeValidRandomHexPad
100
     * @throws InvalidArgument
101
     */
102
    public function testCanBeValidRandomHexPad(): void
103
    {
104
        $this->assertNotEmpty(IPFuscator::getRandomHexPad($this->ip));
105
    }
106
107
    /**
108
     * testCanBeValidRandomOctPad
109
     * @throws InvalidArgument
110
     */
111
    public function testCanBeValidRandomOctPad(): void
112
    {
113
        $this->assertNotEmpty(IPFuscator::getRandomOctPad($this->ip));
114
    }
115
116
    /**
117
     * testCanBeValidRandomBase
118
     * @throws InvalidArgument
119
     */
120
    public function testCanBeValidRandomBase(): void
121
    {
122
        $this->assertNotEmpty(IPFuscator::getRandomBase($this->ip));
123
    }
124
125
    /**
126
     * testCanBeValidRandomBaseWithPad
127
     * @throws InvalidArgument
128
     */
129
    public function testCanBeValidRandomBaseWithPad(): void
130
    {
131
        $this->assertNotEmpty(IPFuscator::getRandomBaseWithRandomPad($this->ip));
132
    }
133
}