IpValidatorTest::testInvalidIp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 8
Ratio 100 %

Importance

Changes 0
Metric Value
dl 8
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
/**
3
 * @link https://github.com/yiiviet/yii2-validator
4
 * @copyright Copyright (c) 2018 Yii Viet
5
 * @license [New BSD License](http://www.opensource.org/licenses/bsd-license.php)
6
 */
7
8
namespace yiiviet\tests\unit\validator;
9
10
use yii\base\DynamicModel;
11
12
/**
13
 * Lớp IpValidatorTest
14
 *
15
 * @author Vuong Minh <[email protected]>
16
 * @since 1.0
17
 */
18 View Code Duplication
class IpValidatorTest extends TestCase
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
19
{
20
21
    /**
22
     * @dataProvider validIpProvider
23
     */
24
    public function testValidIp($ip)
25
    {
26
        $model = DynamicModel::validateData(['ip' => $ip], [
27
            ['ip', 'ipvn']
28
        ]);
29
30
        $this->assertFalse($model->hasErrors());
31
    }
32
33
    /**
34
     * @dataProvider invalidIpProvider
35
     */
36
    public function testInvalidIp($ip)
37
    {
38
        $model = DynamicModel::validateData(['ip' => $ip], [
39
            ['ip', 'ipvn']
40
        ]);
41
42
        $this->assertTrue($model->hasErrors());
43
    }
44
45
46
    public function validIpProvider()
47
    {
48
        return [
49
            ['113.161.173.10'],
50
            ['171.255.199.129'],
51
            ['118.70.187.126'],
52
            ['115.78.225.211'],
53
            ['2405:4800:102:1::3'],
54
            ['2001:df0:66:40::16']
55
        ];
56
    }
57
58
    public function invalidIpProvider()
59
    {
60
        return [
61
            ['217.24.254.30'],
62
            ['82.114.86.1'],
63
            ['200.114.80.9'],
64
            ['190.123.83.251'],
65
            ['190.123.83.251'],
66
            ['190.123.83.251'],
67
            ['139.199.201.249'],
68
            ['52.80.73.123'],
69
            ['2a03:2880:f11f:83:face:b00c::25de'],
70
            ['2a00:1450:4007:809::200e']
71
        ];
72
    }
73
}
74