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) { |
|
|
|
|
74
|
|
|
} catch (Exception $e) { |
|
|
|
|
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function testCanBeValidRandomOctPad(): void |
79
|
|
|
{ |
80
|
|
|
try { |
81
|
|
|
$this->assertNotEmpty(IPFuscator::getRandomOctPad($this->ip)); |
82
|
|
|
} catch (InvalidArgument $e) { |
|
|
|
|
83
|
|
|
} catch (Exception $e) { |
|
|
|
|
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function testCanBeValidRandomBase(): void |
88
|
|
|
{ |
89
|
|
|
try { |
90
|
|
|
$this->assertNotEmpty(IPFuscator::getRandomBase($this->ip)); |
91
|
|
|
} catch (InvalidArgument $e) { |
|
|
|
|
92
|
|
|
} catch (Exception $e) { |
|
|
|
|
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function testCanBeValidRandomBaseWithPad(): void |
97
|
|
|
{ |
98
|
|
|
try { |
99
|
|
|
$this->assertNotEmpty(IPFuscator::getRandomBaseWithRandomPad($this->ip)); |
100
|
|
|
} catch (InvalidArgument $e) { |
|
|
|
|
101
|
|
|
} catch (Exception $e) { |
|
|
|
|
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
} |