WildcardTest::testIsValidValidWithTwoWildcards()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace OpCacheGUITest\Unit\Network\Ip;
4
5
use OpCacheGUI\Network\Ip\Converter;
6
use OpCacheGUI\Network\Ip\Wildcard;
7
use PHPUnit\Framework\TestCase;
8
9
class WildcardTest extends TestCase
10
{
11
    /**
12
     */
13
    public function testConstructCorrectInstance()
14
    {
15
        $ipRange = new Wildcard();
16
17
        $this->assertInstanceOf(Converter::class, $ipRange);
18
    }
19
20
    /**
21
     * @covers OpCacheGUI\Network\Ip\Wildcard::isValid
22
     */
23
    public function testIsValidValidWithOneWildcard()
24
    {
25
        $ipRange = new Wildcard();
26
27
        $this->assertTrue($ipRange->isValid('10.0.0.*'));
28
    }
29
30
    /**
31
     * @covers OpCacheGUI\Network\Ip\Wildcard::isValid
32
     */
33
    public function testIsValidValidWithTwoWildcards()
34
    {
35
        $ipRange = new Wildcard();
36
37
        $this->assertTrue($ipRange->isValid('10.0.*.*'));
38
    }
39
40
    /**
41
     * @covers OpCacheGUI\Network\Ip\Wildcard::isValid
42
     */
43
    public function testIsValidValidWithThreeWildcards()
44
    {
45
        $ipRange = new Wildcard();
46
47
        $this->assertTrue($ipRange->isValid('10.*.*.*'));
48
    }
49
50
    /**
51
     * @covers OpCacheGUI\Network\Ip\Wildcard::isValid
52
     */
53
    public function testIsValidNotValidCidr()
54
    {
55
        $ipRange = new Wildcard();
56
57
        $this->assertFalse($ipRange->isValid('127.0.0.1/32'));
58
    }
59
60
    /**
61
     * @covers OpCacheGUI\Network\Ip\Wildcard::isValid
62
     */
63
    public function testIsValidNotValidLocalhost()
64
    {
65
        $ipRange = new Wildcard();
66
67
        $this->assertFalse($ipRange->isValid('localhost'));
68
    }
69
70
    /**
71
     * @covers OpCacheGUI\Network\Ip\Wildcard::isValid
72
     */
73
    public function testIsValidNotValidSingle()
74
    {
75
        $ipRange = new Wildcard();
76
77
        $this->assertFalse($ipRange->isValid('127.0.0.1'));
78
    }
79
80
    /**
81
     * @covers OpCacheGUI\Network\Ip\Wildcard::isValid
82
     */
83
    public function testIsValidNotValidRange()
84
    {
85
        $ipRange = new Wildcard();
86
87
        $this->assertFalse($ipRange->isValid('10.0.0.1-10.0.0.5'));
88
    }
89
90
    /**
91
     * @covers OpCacheGUI\Network\Ip\Wildcard::isValid
92
     */
93
    public function testIsValidNotValidAllWildcards()
94
    {
95
        $ipRange = new Wildcard();
96
97
        $this->assertFalse($ipRange->isValid('*.*.*.*'));
98
    }
99
100
    /**
101
     * @covers OpCacheGUI\Network\Ip\Wildcard::convert
102
     */
103
    public function testConvertOneWildcard()
104
    {
105
        $ipRange = new Wildcard();
106
107
        $this->assertSame([2130706432.0, 2130706687.0], $ipRange->convert('127.0.0.*'));
108
    }
109
110
    /**
111
     * @covers OpCacheGUI\Network\Ip\Wildcard::convert
112
     */
113
    public function testConvertTwoWildcards()
114
    {
115
        $ipRange = new Wildcard();
116
117
        $this->assertSame([2130706432.0, 2130771967.0], $ipRange->convert('127.0.*.*'));
118
    }
119
120
    /**
121
     * @covers OpCacheGUI\Network\Ip\Wildcard::convert
122
     */
123
    public function testConvertThreeWildcards()
124
    {
125
        $ipRange = new Wildcard();
126
127
        $this->assertSame([2130706432.0, 2147483647.0], $ipRange->convert('127.*.*.*'));
128
    }
129
}
130