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

Nsec3Test   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 4
dl 0
loc 82
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getDataProvider() 0 7 1
A testGetType() 0 5 1
A testGetTypeCode() 0 5 1
A testToText() 0 12 1
A testWire() 0 15 1
A testFromText() 0 11 1
A testFactory() 0 6 1
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\NSEC3;
18
use Base32\Base32Hex;
19
use PHPUnit\Framework\TestCase;
20
21
class Nsec3Test extends TestCase
22
{
23
    public function getDataProvider(): array
24
    {
25
        return [
26
            ['1 1 10 12345678 589R358VSPJUFVAJU949JPVF74D9PTGH A RRSIG', true, 10, '12345678', 'ns.sub.delzsk.example.', ['A', 'RRSIG'], '589R358VSPJUFVAJU949JPVF74D9PTGH'],
27
            ['1 0 10 - JGU2L7C3LKLHAKC5RHUOORTI2DCKK3KL TXT RRSIG', false, 10, '', 'a.test.', ['TXT', 'RRSIG'], 'JGU2L7C3LKLHAKC5RHUOORTI2DCKK3KL'],
28
        ];
29
    }
30
31
    public function testGetType(): void
32
    {
33
        $nsec3 = new NSEC3();
34
        $this->assertEquals('NSEC3', $nsec3->getType());
35
    }
36
37
    public function testGetTypeCode(): void
38
    {
39
        $nsec3 = new NSEC3();
40
        $this->assertEquals(50, $nsec3->getTypeCode());
41
    }
42
43
    /**
44
     * @dataProvider getDataProvider
45
     */
46
    public function testToText(string $text, bool $unsignedDelegationsCovered, int $iterations, string $salt, string $nextOwnerName, array $types, string $nextHashedOwnerName): void
0 ignored issues
show
Unused Code introduced by
The parameter $nextHashedOwnerName is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
47
    {
48
        $nsec3 = new NSEC3();
49
        $nsec3->setUnsignedDelegationsCovered($unsignedDelegationsCovered);
50
        $nsec3->setIterations($iterations);
51
        $nsec3->setSalt($salt);
52
        $nsec3->setNextOwnerName($nextOwnerName);
53
        $nsec3->setTypes($types);
54
        $nsec3->calculateNextOwnerHash();
55
56
        $this->assertEquals($text, $nsec3->toText());
57
    }
58
59
    /**
60
     * @dataProvider getDataProvider
61
     */
62
    public function testWire(string $text, bool $unsignedDelegationsCovered, int $iterations, string $salt, string $nextOwnerName, array $types, string $nextHashedOwnerName): void
0 ignored issues
show
Unused Code introduced by
The parameter $text is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $nextOwnerName is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
63
    {
64
        $nsec3 = new NSEC3();
65
        $nsec3->setUnsignedDelegationsCovered($unsignedDelegationsCovered);
66
        $nsec3->setIterations($iterations);
67
        $nsec3->setSalt($salt);
68
        $nsec3->setNextHashedOwnerName(Base32Hex::decode($nextHashedOwnerName));
69
        $nsec3->setTypes($types);
70
71
        $wireFormat = $nsec3->toWire();
72
73
        $fromWire = new NSEC3();
74
        $fromWire->fromWire($wireFormat);
75
        $this->assertEquals($nsec3, $fromWire);
76
    }
77
78
    /**
79
     * @dataProvider getDataProvider
80
     */
81
    public function testFromText(string $text, bool $unsignedDelegationsCovered, int $iterations, string $salt, string $nextOwnerName, array $types, string $nextHashedOwnerName): void
0 ignored issues
show
Unused Code introduced by
The parameter $nextOwnerName is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
82
    {
83
        $fromText = new NSEC3();
84
        $fromText->fromText($text);
85
86
        $this->assertEquals($fromText->isUnsignedDelegationsCovered(), $unsignedDelegationsCovered);
87
        $this->assertEquals($fromText->getIterations(), $iterations);
88
        $this->assertEquals($fromText->getSalt(), $salt);
89
        $this->assertEquals($fromText->getTypes(), $types);
90
        $this->assertEquals($fromText->getNextHashedOwnerName(), Base32Hex::decode($nextHashedOwnerName));
91
    }
92
93
    /**
94
     * @dataProvider getDataProvider
95
     */
96
    public function testFactory(string $text, bool $unsignedDelegationsCovered, int $iterations, string $salt, string $nextOwnerName, array $types, string $nextHashedOwnerName): void
97
    {
98
        $nsec3 = Factory::NSEC3($unsignedDelegationsCovered, $iterations, $salt, $nextOwnerName, $types);
99
        $this->assertEquals($nextHashedOwnerName, Base32Hex::encode($nsec3->getNextHashedOwnerName()));
100
        $this->assertEquals($text, $nsec3->toText());
101
    }
102
}
103