|
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\DNAME; |
|
17
|
|
|
use PHPUnit\Framework\TestCase; |
|
18
|
|
|
|
|
19
|
|
View Code Duplication |
class DnameTest extends TestCase |
|
|
|
|
|
|
20
|
|
|
{ |
|
21
|
|
|
public function testSetTarget(): void |
|
22
|
|
|
{ |
|
23
|
|
|
$target = 'foo.example.com.'; |
|
24
|
|
|
$dname = new DNAME(); |
|
25
|
|
|
$dname->setTarget($target); |
|
26
|
|
|
|
|
27
|
|
|
$this->assertEquals($target, $dname->getTarget()); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function testOutput(): void |
|
31
|
|
|
{ |
|
32
|
|
|
$target = 'foo.example.com.'; |
|
33
|
|
|
$dname = new DNAME(); |
|
34
|
|
|
$dname->setTarget($target); |
|
35
|
|
|
|
|
36
|
|
|
$this->assertEquals($target, $dname->toText()); |
|
37
|
|
|
$this->assertEquals($target, $dname->toText()); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function testFromText(): void |
|
41
|
|
|
{ |
|
42
|
|
|
$text = 'host.example.com.'; |
|
43
|
|
|
/** @var DNAME $cname */ |
|
44
|
|
|
$cname = new DNAME(); |
|
45
|
|
|
$cname->fromText($text); |
|
46
|
|
|
|
|
47
|
|
|
$this->assertEquals($text, $cname->getTarget()); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function testWire(): void |
|
51
|
|
|
{ |
|
52
|
|
|
$host = 'host.example.com.'; |
|
53
|
|
|
$expectation = chr(4).'host'.chr(7).'example'.chr(3).'com'.chr(0); |
|
54
|
|
|
|
|
55
|
|
|
/** @var DNAME $dname */ |
|
56
|
|
|
$dname = new DNAME(); |
|
57
|
|
|
$dname->fromWire($expectation); |
|
58
|
|
|
|
|
59
|
|
|
$this->assertEquals($expectation, $dname->toWire()); |
|
60
|
|
|
$this->assertEquals($host, $dname->getTarget()); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
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.