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

CnameTest::testOutput()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
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\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