testOutputThrowsExceptionWhenMissingExchange()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
dl 9
loc 9
rs 9.9666
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\MX;
17
use PHPUnit\Framework\TestCase;
18
19
class MxTest extends TestCase
20
{
21
    public function testSetters(): void
22
    {
23
        $target = 'foo.example.com.';
24
        $preference = 10;
25
        $mx = new MX();
26
        $mx->setExchange($target);
27
        $mx->setPreference($preference);
28
29
        $this->assertEquals($target, $mx->getExchange());
30
        $this->assertEquals($preference, $mx->getPreference());
31
    }
32
33
    public function testOutput(): void
34
    {
35
        $target = 'foo.example.com.';
36
        $mx = new MX();
37
        $mx->SetExchange($target);
38
        $mx->setPreference(42);
39
40
        $this->assertEquals('42 foo.example.com.', $mx->toText());
41
    }
42
43 View Code Duplication
    public function testOutputThrowsExceptionWhenMissingPreference(): 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...
44
    {
45
        $mx = new MX();
46
        $mx->setExchange('mail.google.com.');
47
48
        $this->expectException(\InvalidArgumentException::class);
49
        $this->expectExceptionMessage('No preference has been set on MX object.');
50
        $mx->toText();
51
    }
52
53 View Code Duplication
    public function testOutputThrowsExceptionWhenMissingExchange(): 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...
54
    {
55
        $mx = new MX();
56
        $mx->setPreference(15);
57
58
        $this->expectException(\InvalidArgumentException::class);
59
        $this->expectExceptionMessage('No exchange has been set on MX object.');
60
        $mx->toText();
61
    }
62
63 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...
64
    {
65
        $text = '10 mail.example.com.';
66
        /** @var MX $mx */
67
        $mx = new MX();
68
        $mx->fromText($text);
69
70
        $this->assertEquals(10, $mx->getPreference());
71
        $this->assertEquals('mail.example.com.', $mx->getExchange());
72
    }
73
74 View Code Duplication
    public function testWire(): 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...
75
    {
76
        $mx = new MX();
77
        $mx->setExchange('mail.example.com.');
78
        $mx->setPreference(10);
79
80
        $expectation = pack('n', 10).chr(4).'mail'.chr(7).'example'.chr(3).'com'.chr(0);
81
82
        $this->assertEquals($expectation, $mx->toWire());
83
        $fromWire = new MX();
84
        $fromWire->fromWire($expectation);
85
        $this->assertEquals($mx, $fromWire);
86
    }
87
}
88