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

CnameTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testOutput() 0 8 1
A testFromText() 0 9 1
A testWire() 0 18 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\CNAME;
17
use PHPUnit\Framework\TestCase;
18
19
class CnameTest extends TestCase
20
{
21
    public function testOutput(): void
22
    {
23
        $target = 'foo.example.com.';
24
        $cname = new CNAME();
25
        $cname->setTarget($target);
26
27
        $this->assertEquals($target, $cname->toText());
28
    }
29
30
    public function testFromText(): void
31
    {
32
        $text = 'host.example.com.';
33
        /** @var CNAME $cname */
34
        $cname = new CNAME();
35
        $cname->fromText($text);
36
37
        $this->assertEquals($text, $cname->getTarget());
38
    }
39
40
    public function testWire(): void
41
    {
42
        $host = 'host.example.com.';
43
        $expectation = chr(4).'host'.chr(7).'example'.chr(3).'com'.chr(0);
44
45
        /** @var CNAME $cname */
46
        $cname = new CNAME();
47
        $cname->fromWire($expectation);
48
49
        $this->assertEquals($expectation, $cname->toWire());
50
        $this->assertEquals($host, $cname->getTarget());
51
52
        //Test that toWire() will throw an exception if no target is set.
53
        $cname = new CNAME();
54
        $this->expectException(\InvalidArgumentException::class);
55
        $this->expectExceptionMessage('Target must be set.');
56
        $cname->toWire();
57
    }
58
}
59