Completed
Pull Request — master (#97)
by Sam
04:21
created

ReverseTest::testReverseIpv4Record()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 38

Duplication

Lines 38
Ratio 100 %

Importance

Changes 0
Metric Value
dl 38
loc 38
rs 9.312
c 0
b 0
f 0
cc 1
nc 1
nop 0
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;
15
16
use Badcow\DNS\Classes;
17
use Badcow\DNS\Rdata\Factory;
18
use Badcow\DNS\Rdata\PTR;
19
use Badcow\DNS\ResourceRecord;
20
use Badcow\DNS\Zone;
21
use Badcow\DNS\ZoneBuilder;
22
use PHPUnit\Framework\TestCase;
23
24
class ReverseTest extends TestCase
25
{
26
    /**
27
     * @var string
28
     */
29
    private $expectedIpv4Record = <<< 'TXT'
30
$ORIGIN 8.168.192.in-addr.arpa.
31
$TTL 14400
32
@ IN SOA example.com. post.example.com. 2015010101 3600 14400 604800 3600
33
@ IN NS ns1.example.com.
34
@ IN NS ns2.example.com.
35
1 IN PTR foo1.example.com.
36
2 IN PTR foo2.example.com.
37
3 IN PTR foo3.example.com.
38
4 IN PTR foo4.example.com.
39
5 IN PTR foo5.example.com.
40
41
TXT;
42
43
    /**
44
     * @var string
45
     */
46
    private $expectedIpv6Record = <<< 'TXT'
47
$ORIGIN 1.2.0.0.3.8.f.0.1.0.0.2.ip6.arpa.
48
$TTL 14400
49
@ IN SOA example.com. post.example.com. 2015010101 3600 14400 604800 3600
50
@ IN NS ns1.example.com.
51
@ IN NS ns2.example.com.
52
8 IN PTR foo8.example.com.
53
9 IN PTR foo9.example.com.
54
a IN PTR fooa.example.com.
55
b IN PTR foob.example.com.
56
c IN PTR fooc.example.com.
57
58
TXT;
59
60
    protected function setUp(): void
61
    {
62
        $this->expectedIpv4Record = str_replace("\r", '', $this->expectedIpv4Record);
63
        $this->expectedIpv6Record = str_replace("\r", '', $this->expectedIpv6Record);
64
    }
65
66 View Code Duplication
    public function testReverseIpv4Record(): void
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...
67
    {
68
        $origin = PTR::reverseIpv4('192.168.8');
69
70
        $soa = ResourceRecord::create('@', Factory::SOA(
71
            'example.com.',
72
            'post.example.com.',
73
            2015010101,
74
            3600,
75
            14400,
76
            604800,
77
            3600
78
        ), null, Classes::INTERNET);
79
80
        $ns1 = ResourceRecord::create('@', Factory::NS('ns1.example.com.'), null, Classes::INTERNET);
81
        $ns2 = ResourceRecord::create('@', Factory::NS('ns2.example.com.'), null, Classes::INTERNET);
82
83
        $foo1 = ResourceRecord::create('1', Factory::PTR('foo1.example.com.'), null, Classes::INTERNET);
84
        $foo2 = ResourceRecord::create('2', Factory::PTR('foo2.example.com.'), null, Classes::INTERNET);
85
        $foo3 = ResourceRecord::create('3', Factory::PTR('foo3.example.com.'), null, Classes::INTERNET);
86
        $foo4 = ResourceRecord::create('4', Factory::PTR('foo4.example.com.'), null, Classes::INTERNET);
87
        $foo5 = ResourceRecord::create('5', Factory::PTR('foo5.example.com.'), null, Classes::INTERNET);
88
89
        $zone = new Zone($origin, 14400, [
90
            $soa,
91
            $ns1,
92
            $ns2,
93
            $foo1,
94
            $foo2,
95
            $foo3,
96
            $foo4,
97
            $foo5,
98
        ]);
99
100
        $builder = new ZoneBuilder();
101
102
        $this->assertEquals($this->expectedIpv4Record, $builder->build($zone));
103
    }
104
105 View Code Duplication
    public function testReverseIpv6Record(): void
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...
106
    {
107
        $origin = PTR::reverseIpv6('2001:f83:21');
108
109
        $soa = ResourceRecord::create('@', Factory::SOA(
110
            'example.com.',
111
            'post.example.com.',
112
            2015010101,
113
            3600,
114
            14400,
115
            604800,
116
            3600
117
        ), null, Classes::INTERNET);
118
119
        $ns1 = ResourceRecord::create('@', Factory::NS('ns1.example.com.'), null, Classes::INTERNET);
120
        $ns2 = ResourceRecord::create('@', Factory::NS('ns2.example.com.'), null, Classes::INTERNET);
121
122
        $foo8 = ResourceRecord::create('8', Factory::PTR('foo8.example.com.'), null, Classes::INTERNET);
123
        $foo9 = ResourceRecord::create('9', Factory::PTR('foo9.example.com.'), null, Classes::INTERNET);
124
        $fooa = ResourceRecord::create('a', Factory::PTR('fooa.example.com.'), null, Classes::INTERNET);
125
        $foob = ResourceRecord::create('b', Factory::PTR('foob.example.com.'), null, Classes::INTERNET);
126
        $fooc = ResourceRecord::create('c', Factory::PTR('fooc.example.com.'), null, Classes::INTERNET);
127
128
        $zone = new Zone($origin, 14400, [
129
            $soa,
130
            $ns1,
131
            $ns2,
132
            $foo8,
133
            $foo9,
134
            $fooa,
135
            $foob,
136
            $fooc,
137
        ]);
138
139
        $builder = new ZoneBuilder();
140
141
        $this->assertEquals($this->expectedIpv6Record, $builder->build($zone));
142
    }
143
}
144