Completed
Push — master ( 72b670...3b819e )
by Sam
05:26 queued 03:37
created

DlvTest::testFromText()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 13
Ratio 100 %

Importance

Changes 0
Metric Value
dl 13
loc 13
rs 9.8333
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\Algorithms;
17
use Badcow\DNS\Rdata\DLV;
18
use Badcow\DNS\Rdata\Factory;
19
use PHPUnit\Framework\TestCase;
20
21 View Code Duplication
class DlvTest extends TestCase
0 ignored issues
show
Duplication introduced by
This class 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...
22
{
23
    private static $digest = '2BB183AF5F22588179A53B0A98631FAD1A292118';
24
25
    public function testFactory(): void
26
    {
27
        $keyTag = 60485;
28
        $ds = Factory::DLV($keyTag, Algorithms::RSASHA1, hex2bin(self::$digest), DLV::DIGEST_SHA1);
29
30
        $this->assertEquals($keyTag, $ds->getKeyTag());
31
        $this->assertEquals(Algorithms::RSASHA1, $ds->getAlgorithm());
32
        $this->assertEquals(hex2bin(self::$digest), $ds->getDigest());
33
        $this->assertEquals(DLV::DIGEST_SHA1, $ds->getDigestType());
34
    }
35
36
    public function testFromText(): void
37
    {
38
        $expectation = new DLV();
39
        $expectation->setKeyTag(60485);
40
        $expectation->setAlgorithm(Algorithms::RSASHA1);
41
        $expectation->setDigestType(DLV::DIGEST_SHA1);
42
        $expectation->setDigest(hex2bin(self::$digest));
43
44
        $dlv = new DLV();
45
        $dlv->fromText('60485 5 1 '.self::$digest);
46
        $this->assertInstanceOf(DLV::class, $dlv);
47
        $this->assertEquals($expectation, $dlv);
48
    }
49
50
    public function testWire(): void
51
    {
52
        $dlv = new DLV();
53
        $dlv->setKeyTag(60485);
54
        $dlv->setAlgorithm(Algorithms::RSASHA1);
55
        $dlv->setDigestType(DLV::DIGEST_SHA1);
56
        $dlv->setDigest(hex2bin(self::$digest));
57
        $wireFormat = $dlv->toWire();
58
        $fromWire = new DLV();
59
        $fromWire->fromWire($wireFormat);
60
61
        $this->assertInstanceOf(DLV::class, $fromWire);
62
        $this->assertEquals($dlv, $fromWire);
63
    }
64
}
65