IpUtilTest::ip2decValues()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 0
1
<?php
2
3
namespace Ip2c\Test\Unit;
4
5
use Ip2c\Http\Http;
6
use Ip2c\Ip\IpUtil;
7
use Prophecy\Argument;
8
9
class IpUtilTest extends \PHPUnit_Framework_TestCase
10
{
11
12
    /** @var IpUtil */
13
    private $sut;
14
15
    public function setUp()
16
    {
17
        $this->sut = new IpUtil();
18
    }
19
20
    public function testShouldBeInstantiated()
21
    {
22
        $this->assertInstanceOf('Ip2c\Ip\IpUtil', $this->sut);
23
    }
24
25
    /**
26
     * @dataProvider ip2decValues
27
     */
28
    public function testShouldReturnCorrectValue($ip, $ipDec)
29
    {
30
        $ipCalculated = $this->sut->ip2long($ip);
31
32
        $this->assertEquals($ipDec, $ipCalculated);
33
    }
34
35
    public function testShouldReturnFalse()
36
    {
37
        $this->assertFalse($this->sut->ip2long('123.456.'));
38
        $this->assertFalse($this->sut->ip2long('123.456.654'));
39
        $this->assertFalse($this->sut->ip2long('123.123.123.'));
40
        $this->assertFalse($this->sut->ip2long('123.123.123.458'));
41
    }
42
    public function ip2decValues()
43
    {
44
        $ips2test = array();
45
46
        for ($i = 0; $i < 10; $i++) {
47
            $newIp = $this->generateIp();
48
            $ips2test[] = array($newIp, ip2long($newIp));
49
        }
50
51
        return $ips2test;
52
    }
53
54
    private function generateIp()
55
    {
56
        return rand(1, 255) . "." . rand(1, 255) . "." . rand(1, 255) . "." . rand(1, 255);
57
    }
58
}
59