Completed
Push — master ( 3d7536...3ced6b )
by Marcin
02:56
created

IPv4Test::testIpv4IntValid()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
dl 9
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
/**
3
 * Validator
4
 *
5
 * Copyright (c) 2017 pudelek.org.pl
6
 *
7
 * @license MIT License (MIT)
8
 *
9
 * For the full copyright and license information, please view source file
10
 * that is bundled with this package in the file LICENSE
11
 *
12
 * @author Marcin Pudełek <[email protected]>
13
 */
14
15
namespace mrcnpdlk\Validator;
16
17
use mrcnpdlk\Validator\Types\IPv4;
18
19
class IPv4Test extends TestCase
20
{
21 View Code Duplication
    public function testIpv4IntValid()
0 ignored issues
show
Duplication introduced by
This method 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...
22
    {
23
        $defNr = 1527088647;
24
        $this->assertTrue(IPv4::isValid($defNr, false));
25
        $res   = new IPv4($defNr);
26
        $this->assertEquals('91.5.134.7', $res->get());
27
        $this->assertEquals('091.005.134.007', $res->getLeadingZeros());
28
        $this->assertEquals(1527088647, $res->getLong());
29
    }
30
31 View Code Duplication
    public function testIpv4StringValid()
0 ignored issues
show
Duplication introduced by
This method 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...
32
    {
33
        $defNr = '91.5.134.007';
34
        $this->assertTrue(IPv4::isValid($defNr, false));
35
        $res   = new IPv4($defNr);
36
        $this->assertEquals('91.5.134.7', $res->get());
37
        $this->assertEquals('091.005.134.007', $res->getLeadingZeros());
38
        $this->assertEquals(1527088647, $res->getLong());
39
    }
40
41
    /**
42
     * @expectedException \mrcnpdlk\Validator\Exception
43
     */
44
    public function testIpv4InvalidValid()
45
    {
46
        IPv4::isValid('1.1.1.300',true);
47
    }
48
    public function testIpv4Local()
49
    {
50
        $this->assertTrue((new IPv4('127.0.0.1'))->isLocalIPAddress());
51
        $this->assertTrue((new IPv4('10.0.0.1'))->isLocalIPAddress());
52
        $this->assertTrue((new IPv4('10.255.255.255'))->isLocalIPAddress());
53
        $this->assertTrue((new IPv4('172.16.0.1'))->isLocalIPAddress());
54
        $this->assertTrue((new IPv4('172.31.255.255'))->isLocalIPAddress());
55
        $this->assertTrue((new IPv4('192.168.0.1'))->isLocalIPAddress());
56
        $this->assertTrue((new IPv4('192.168.255.254'))->isLocalIPAddress());
57
    }
58
59
60
}
61