SrvTest::testWeightException()   A
last analyzed

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\Factory;
17
use Badcow\DNS\Rdata\SRV;
18
use PHPUnit\Framework\TestCase;
19
20
class SrvTest extends TestCase
21
{
22 View Code Duplication
    public function testOutput(): void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
23
    {
24
        $srv = Factory::SRV(10, 20, 666, 'doom.example.com.');
25
26
        $expectation = '10 20 666 doom.example.com.';
27
28
        $this->assertEquals($expectation, $srv->toText());
29
        $this->assertEquals(10, $srv->getPriority());
30
        $this->assertEquals(20, $srv->getWeight());
31
        $this->assertEquals(666, $srv->getPort());
32
    }
33
34
    /**
35
     * @throws \InvalidArgumentException
36
     */
37
    public function testPortException(): void
38
    {
39
        $this->expectException(\InvalidArgumentException::class);
40
        $this->expectExceptionMessage('Port must be an unsigned integer on the range [0-65535]');
41
42
        $srv = new SRV();
43
        $srv->setPort(65536);
44
    }
45
46
    /**
47
     * @throws \InvalidArgumentException
48
     */
49
    public function testPriorityException(): void
50
    {
51
        $this->expectException(\InvalidArgumentException::class);
52
        $this->expectExceptionMessage('Priority must be an unsigned integer on the range [0-65535]');
53
54
        $srv = new SRV();
55
        $srv->setPriority(65536);
56
    }
57
58
    /**
59
     * @throws \InvalidArgumentException
60
     */
61
    public function testWeightException(): void
62
    {
63
        $this->expectException(\InvalidArgumentException::class);
64
        $this->expectExceptionMessage('Weight must be an unsigned integer on the range [0-65535]');
65
66
        $srv = new SRV();
67
        $srv->setWeight(65536);
68
    }
69
70 View Code Duplication
    public function testFromText(): void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
71
    {
72
        $text = '0 1 80 www.example.com.';
73
        $srv = new SRV();
74
        $srv->setPriority(0);
75
        $srv->setWeight(1);
76
        $srv->setPort(80);
77
        $srv->setTarget('www.example.com.');
78
79
        $fromText = new SRV();
80
        $fromText->fromText($text);
81
        $this->assertEquals($srv, $fromText);
82
    }
83
84
    public function testWire(): void
85
    {
86
        $expectation = pack('nnn', 0, 1, 80).chr(3).'www'.chr(7).'example'.chr(3).'com'.chr(0);
87
        $srv = new SRV();
88
        $srv->setPriority(0);
89
        $srv->setWeight(1);
90
        $srv->setPort(80);
91
        $srv->setTarget('www.example.com.');
92
93
        $this->assertEquals($expectation, $srv->toWire());
94
        $fromWire = new SRV();
95
        $fromWire->fromWire($expectation);
96
        $this->assertEquals($srv, $fromWire);
97
    }
98
}
99