PtrTest   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 68
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A provider_expandIPv6() 0 12 1
A provider_contractIPv6() 0 8 1
A testExpandIpv6() 0 4 1
A testContractIpv6() 0 4 1
A testContractIpv6ThrowsException() 0 7 1
A testReverseIpv4() 0 7 1
A testReverseIpv6() 0 11 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Badcow DNS Library.
7
 *
8
 * (c) Samuel Williams <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Badcow\DNS\Tests\Rdata;
15
16
use Badcow\DNS\Rdata\PTR;
17
use PHPUnit\Framework\TestCase;
18
19
class PtrTest extends TestCase
20
{
21
    public function provider_expandIPv6(): array
22
    {
23
        return [
24
            ['0000:0000:0000:0000:0000:0000:0000:0001', '::1'],
25
            ['2001:0db8:0000:0000:0000:ff00:0042:8329', '2001:db8::ff00:42:8329'],
26
            ['2001:0000:0000:acad:0000:0000:0000:0001', '2001:0:0:acad::1'],
27
            ['0000:0000:0000:0000:0000:0000:0000:0000', '::'],
28
            ['2001:0000:0000:ab80:2390:0000:0000:000a', '2001::ab80:2390:0:0:a'],
29
            ['0000:0000:aaaa:0000:0000:aaaa:0000:0000', '::aaaa:0:0:aaaa:0:0'],
30
            ['0001:0000:0000:0000:0000:0000:0000:0000', '1::'],
31
        ];
32
    }
33
34
    public function provider_contractIPv6(): array
35
    {
36
        return array_merge($this->provider_expandIPv6(), [
37
            ['2001:db8:0:0:f:0:0:0', '2001:db8:0:0:f::'],
38
            ['2001:db8::ff00:42:8329', '2001:db8::ff00:42:8329'],
39
            ['2001:db8:a:bac:8099:d:f:9', '2001:db8:a:bac:8099:d:f:9'],
40
        ]);
41
    }
42
43
    /**
44
     * @dataProvider provider_expandIPv6
45
     */
46
    public function testExpandIpv6(string $expectation, string $ip): void
47
    {
48
        $this->assertEquals($expectation, PTR::expandIpv6($ip));
49
    }
50
51
    /**
52
     * @dataProvider provider_contractIPv6
53
     */
54
    public function testContractIpv6(string $ip, string $expectation): void
55
    {
56
        $this->assertEquals($expectation, PTR::contractIpv6($ip));
57
    }
58
59
    public function testContractIpv6ThrowsException(): void
60
    {
61
        $this->expectException(\InvalidArgumentException::class);
62
        $this->expectExceptionMessage('"127.0.0.1" is not a valid IPv6 address.');
63
64
        PTR::contractIpv6('127.0.0.1');
65
    }
66
67
    public function testReverseIpv4(): void
68
    {
69
        $case_1 = '192.168.1.213';
70
        $exp_1 = '213.1.168.192.in-addr.arpa.';
71
72
        $this->assertEquals($exp_1, PTR::reverseIpv4($case_1));
73
    }
74
75
    public function testReverseIpv6(): void
76
    {
77
        $case_1 = '2001:db8::567:89ab';
78
        $case_2 = '8007:ea:19';
79
80
        $exp_1 = 'b.a.9.8.7.6.5.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa.';
81
        $exp_2 = '9.1.0.0.a.e.0.0.7.0.0.8.ip6.arpa.';
82
83
        $this->assertEquals($exp_1, PTR::reverseIpv6($case_1));
84
        $this->assertEquals($exp_2, PTR::reverseIpv6($case_2));
85
    }
86
}
87