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

TxtTest::testWire()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 11
Ratio 100 %

Importance

Changes 0
Metric Value
dl 11
loc 11
rs 9.9
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\TXT;
17
use PHPUnit\Framework\TestCase;
18
19
class TxtTest extends TestCase
20
{
21
    public function testSetText(): void
22
    {
23
        $text = 'This is some text. It\'s a nice piece of text.';
24
        $txt = new TXT();
25
        $txt->setText($text);
26
27
        $this->assertEquals($text, $txt->getText());
28
    }
29
30
    public function dp_testToText(): array
31
    {
32
        return [
33
            //[$text, $expectation]
34
            ['"This is some quoted text". It\'s a nice piece of text.', '"\"This is some quoted text\". It\'s a nice piece of text."'],
35
            [
36
                'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis vel lorem in massa elementum blandit nec sed massa. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec eu purus id arcu venenatis elementum in quis enim. Aenean at urna varius sapien dapibus.',
37
                '"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis vel lorem in massa elementum blandit nec sed massa. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec eu purus id arcu venenatis elementum in quis enim. Aenean at urna varius sapie" "n dapibus."',
38
            ],
39
        ];
40
    }
41
42
    /**
43
     * @dataProvider dp_testToText
44
     *
45
     * @param string $text        the input text value
46
     * @param string $expectation The expected output of TXT::toText()
47
     */
48
    public function testToText(string $text, string $expectation): void
49
    {
50
        $txt = new TXT();
51
        $txt->setText($text);
52
53
        $this->assertEquals($expectation, $txt->toText());
54
    }
55
56
    public function dp_testFromTxt(): array
57
    {
58
        return [
59
            //[$text, $expectation]
60
            ['"Some text;" " another some text"', 'Some text; another some text'],
61
            ['foobar', 'foobar'],
62
            ['foo bar', 'foo'],
63
            ["\t\t\tfoobar", 'foobar'],
64
            ['3600', '3600'],
65
        ];
66
    }
67
68
    /**
69
     * @dataProvider dp_testFromTxt
70
     */
71
    public function testFromTxt(string $text, string $expectation): void
72
    {
73
        $txt = new TXT();
74
        $txt->fromText($text);
75
        $this->assertEquals($expectation, $txt->getText());
76
    }
77
78 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...
79
    {
80
        $expectation = 'This is some text. It\'s a nice piece of text.';
81
        $txt = new TXT();
82
        $txt->setText($expectation);
83
84
        $this->assertEquals($expectation, $txt->toWire());
85
        $fromWire = new TXT();
86
        $fromWire->fromWire($expectation);
87
        $this->assertEquals($txt, $fromWire);
88
    }
89
}
90