SpfTest::testToText()   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\SPF;
18
use PHPUnit\Framework\TestCase;
19
20
class SpfTest extends TestCase
21
{
22
    public function testFromText(): void
23
    {
24
        $text = '"v=spf1 ip4:192.0.2.0/24 ip4:198.51.100.123 a -all"';
25
26
        /** @var SPF $spf */
27
        $spf = new SPF();
28
        $spf->fromText($text);
29
30
        $this->assertEquals('SPF', $spf->getType());
31
        $this->assertEquals('v=spf1 ip4:192.0.2.0/24 ip4:198.51.100.123 a -all', $spf->getText());
32
    }
33
34
    public function testToText(): void
35
    {
36
        $spf = new SPF();
37
        $spf->setText('v=spf1 ip4:192.0.2.0/24 ip4:198.51.100.123 a -all');
38
39
        $this->assertEquals('"v=spf1 ip4:192.0.2.0/24 ip4:198.51.100.123 a -all"', $spf->toText());
40
        $this->assertEquals('SPF', $spf->getType());
41
    }
42
43
    public function testWire(): void
44
    {
45
        $wireFormat = chr(49).'v=spf1 ip4:192.0.2.0/24 ip4:198.51.100.123 a -all';
46
        $offset = 1;
47
        $rdLength = 49;
48
49
        $spf = new SPF();
50
        $spf->setText('v=spf1 ip4:192.0.2.0/24 ip4:198.51.100.123 a -all');
51
52
        $fromWire = new SPF();
53
        $fromWire->fromWire($wireFormat, $offset, $rdLength);
54
        $this->assertEquals($spf, $fromWire);
55
    }
56
57
    public function testFactory(): void
58
    {
59
        $wireFormat = 'v=spf1 ip4:192.0.2.0/24 ip4:198.51.100.123 a -all';
60
61
        $spf = new SPF();
62
        $spf->setText($wireFormat);
63
64
        $this->assertEquals($spf, Factory::SPF($wireFormat));
65
    }
66
}
67