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\AFSDB; |
17
|
|
|
use Badcow\DNS\Rdata\Factory; |
18
|
|
|
use PHPUnit\Framework\TestCase; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* {@link https://tools.ietf.org/html/rfc1183}. |
22
|
|
|
*/ |
23
|
|
|
class AfsdbTest extends TestCase |
24
|
|
|
{ |
25
|
|
|
public function testOutput(): void |
26
|
|
|
{ |
27
|
|
|
$hostname = 'foo.example.com.'; |
28
|
|
|
$afsdb = new AFSDB(); |
29
|
|
|
$afsdb->setHostname($hostname); |
30
|
|
|
$afsdb->setSubType(2); |
31
|
|
|
|
32
|
|
|
$this->assertEquals('2 foo.example.com.', $afsdb->toText()); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
View Code Duplication |
public function testOutputThrowsExceptionWhenMissingSubType(): void |
|
|
|
|
36
|
|
|
{ |
37
|
|
|
$afsdb = new AFSDB(); |
38
|
|
|
$afsdb->setHostname('foo.example.com.'); |
39
|
|
|
|
40
|
|
|
$this->expectException(\InvalidArgumentException::class); |
41
|
|
|
$this->expectExceptionMessage('No sub-type has been set on AFSDB object.'); |
42
|
|
|
$afsdb->toText(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
View Code Duplication |
public function testOutputThrowsExceptionWhenMissingHostname(): void |
|
|
|
|
46
|
|
|
{ |
47
|
|
|
$afsdb = new AFSDB(); |
48
|
|
|
$afsdb->setSubType(15); |
49
|
|
|
|
50
|
|
|
$this->expectException(\InvalidArgumentException::class); |
51
|
|
|
$this->expectExceptionMessage('No hostname has been set on AFSDB object.'); |
52
|
|
|
$afsdb->toText(); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function testFromText(): void |
56
|
|
|
{ |
57
|
|
|
$text = '2 foo.example.com.'; |
58
|
|
|
/** @var AFSDB $afsdb */ |
59
|
|
|
$afsdb = new AFSDB(); |
60
|
|
|
$afsdb->fromText($text); |
61
|
|
|
|
62
|
|
|
$this->assertEquals(2, $afsdb->getSubType()); |
63
|
|
|
$this->assertEquals('foo.example.com.', $afsdb->getHostname()); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
View Code Duplication |
public function testWire(): void |
|
|
|
|
67
|
|
|
{ |
68
|
|
|
$afsdb = new AFSDB(); |
69
|
|
|
$afsdb->setHostname('foo.example.com.'); |
70
|
|
|
$afsdb->setSubType(2); |
71
|
|
|
|
72
|
|
|
$expectation = pack('n', 2).chr(3).'foo'.chr(7).'example'.chr(3).'com'.chr(0); |
73
|
|
|
|
74
|
|
|
$fromWire = new AFSDB(); |
75
|
|
|
$fromWire->fromWire($expectation); |
76
|
|
|
|
77
|
|
|
$this->assertEquals($expectation, $afsdb->toWire()); |
78
|
|
|
$this->assertEquals($afsdb, $fromWire); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function testFactory(): void |
82
|
|
|
{ |
83
|
|
|
$afsdb = Factory::AFSDB(2, 'foo.example.com.'); |
84
|
|
|
|
85
|
|
|
$this->assertInstanceOf(AFSDB::class, $afsdb); |
86
|
|
|
$this->assertEquals('2 foo.example.com.', $afsdb->toText()); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
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.