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\A; |
17
|
|
|
use Badcow\DNS\Rdata\AAAA; |
18
|
|
|
use Badcow\DNS\Rdata\CSYNC; |
19
|
|
|
use Badcow\DNS\Rdata\Factory; |
20
|
|
|
use Badcow\DNS\Rdata\NS; |
21
|
|
|
use PHPUnit\Framework\TestCase; |
22
|
|
|
|
23
|
|
|
class CsyncTest extends TestCase |
24
|
|
|
{ |
25
|
|
|
public function testGetType(): void |
26
|
|
|
{ |
27
|
|
|
$csync = new CSYNC(); |
28
|
|
|
$this->assertEquals('CSYNC', $csync->getType()); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function testGetTypeCode(): void |
32
|
|
|
{ |
33
|
|
|
$csync = new CSYNC(); |
34
|
|
|
$this->assertEquals(62, $csync->getTypeCode()); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function testToText(): void |
38
|
|
|
{ |
39
|
|
|
$csync = new CSYNC(); |
40
|
|
|
$csync->setFlags(3); |
41
|
|
|
$csync->setSoaSerial(66); |
42
|
|
|
$csync->addType(A::TYPE); |
43
|
|
|
$csync->addType(NS::TYPE); |
44
|
|
|
$csync->addType(AAAA::TYPE); |
45
|
|
|
|
46
|
|
|
$this->assertEquals('66 3 A NS AAAA', $csync->toText()); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function testToWire(): void |
50
|
|
|
{ |
51
|
|
|
$csync = new CSYNC(); |
52
|
|
|
$csync->setFlags(3); |
53
|
|
|
$csync->setSoaSerial(66); |
54
|
|
|
$csync->addType(A::TYPE); |
55
|
|
|
$csync->addType(NS::TYPE); |
56
|
|
|
$csync->addType(AAAA::TYPE); |
57
|
|
|
|
58
|
|
|
$expectation = chr(0x00).chr(0x00).chr(0x00).chr(0x42). |
59
|
|
|
chr(0x00).chr(0x03). |
60
|
|
|
chr(0x00).chr(0x04).chr(0x60).chr(0x00).chr(0x00).chr(0x08); |
61
|
|
|
|
62
|
|
|
$this->assertEquals($expectation, $csync->toWire()); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
View Code Duplication |
public function testFromText(): void |
|
|
|
|
66
|
|
|
{ |
67
|
|
|
$csync = new CSYNC(); |
68
|
|
|
$csync->setFlags(3); |
69
|
|
|
$csync->setSoaSerial(66); |
70
|
|
|
$csync->addType(A::TYPE); |
71
|
|
|
$csync->addType(NS::TYPE); |
72
|
|
|
$csync->addType(AAAA::TYPE); |
73
|
|
|
|
74
|
|
|
$fromText = new CSYNC(); |
75
|
|
|
$fromText->fromText('66 3 A NS AAAA'); |
76
|
|
|
$this->assertEquals($csync, $fromText); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @throws \Badcow\DNS\Rdata\DecodeException |
81
|
|
|
* @throws \Badcow\DNS\Rdata\UnsupportedTypeException |
82
|
|
|
*/ |
83
|
|
|
public function testFromWire(): void |
84
|
|
|
{ |
85
|
|
|
$wireFormat = chr(0x00).chr(0x00).chr(0x00).chr(0x42). |
86
|
|
|
chr(0x00).chr(0x03). |
87
|
|
|
chr(0x00).chr(0x04).chr(0x60).chr(0x00).chr(0x00).chr(0x08); |
88
|
|
|
|
89
|
|
|
$expectation = new CSYNC(); |
90
|
|
|
$expectation->setFlags(3); |
91
|
|
|
$expectation->setSoaSerial(66); |
92
|
|
|
$expectation->addType(A::TYPE); |
93
|
|
|
$expectation->addType(NS::TYPE); |
94
|
|
|
$expectation->addType(AAAA::TYPE); |
95
|
|
|
|
96
|
|
|
$fromWire = new CSYNC(); |
97
|
|
|
$fromWire->fromWire($wireFormat); |
98
|
|
|
|
99
|
|
|
$this->assertEquals($expectation, $fromWire); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function testFactory(): void |
103
|
|
|
{ |
104
|
|
|
$types = [A::TYPE, NS::TYPE, AAAA::TYPE]; |
105
|
|
|
$csync = Factory::CSYNC(66, 3, $types); |
106
|
|
|
|
107
|
|
|
$this->assertEquals(66, $csync->getSoaSerial()); |
108
|
|
|
$this->assertEquals(3, $csync->getFlags()); |
109
|
|
|
$this->assertEquals($types, $csync->getTypes()); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function testClearTypes(): void |
113
|
|
|
{ |
114
|
|
|
$csync = new CSYNC(); |
115
|
|
|
$csync->addType('A'); |
116
|
|
|
$this->assertCount(1, $csync->getTypes()); |
|
|
|
|
117
|
|
|
$csync->clearTypes(); |
118
|
|
|
$this->assertCount(0, $csync->getTypes()); |
|
|
|
|
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|
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.