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

Nsec3paramTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 77
Duplicated Lines 29.87 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 23
loc 77
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetType() 0 5 1
A testGetTypeCode() 0 5 1
A testToText() 11 11 1
A testToWire() 0 12 1
A testFromText() 12 12 1
A testFromWire() 0 14 1
A testFactory() 0 9 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\Factory;
18
use Badcow\DNS\Rdata\NSEC3PARAM;
19
use PHPUnit\Framework\TestCase;
20
21
class Nsec3paramTest extends TestCase
22
{
23
    public function testGetType(): void
24
    {
25
        $nsec3param = new NSEC3PARAM();
26
        $this->assertEquals('NSEC3PARAM', $nsec3param->getType());
27
    }
28
29
    public function testGetTypeCode(): void
30
    {
31
        $nsec3param = new NSEC3PARAM();
32
        $this->assertEquals(51, $nsec3param->getTypeCode());
33
    }
34
35 View Code Duplication
    public function testToText(): 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...
36
    {
37
        $nsec3param = new NSEC3PARAM();
38
        $nsec3param->setHashAlgorithm(Algorithms::RSAMD5);
39
        $nsec3param->setSalt('d9143ec07c5977ae');
40
        $nsec3param->setIterations(55);
41
        $nsec3param->setFlags(0);
42
43
        $expectation = '1 0 55 d9143ec07c5977ae';
44
        $this->assertEquals($expectation, $nsec3param->toText());
45
    }
46
47
    public function testToWire(): void
48
    {
49
        $nsec3param = new NSEC3PARAM();
50
        $nsec3param->setHashAlgorithm(Algorithms::RSAMD5);
51
        $nsec3param->setSalt('d9143ec07c5977ae');
52
        $nsec3param->setIterations(55);
53
        $nsec3param->setFlags(0);
54
55
        $expectation = chr(1).chr(0).pack('n', 55).chr(8).hex2bin('d9143ec07c5977ae');
56
57
        $this->assertEquals($expectation, $nsec3param->toWire());
58
    }
59
60 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...
61
    {
62
        $expectation = new NSEC3PARAM();
63
        $expectation->setHashAlgorithm(Algorithms::RSAMD5);
64
        $expectation->setSalt('d9143ec07c5977ae');
65
        $expectation->setIterations(55);
66
        $expectation->setFlags(0);
67
68
        $fromText = new NSEC3PARAM();
69
        $fromText->fromText('1 0 55 d9143ec07c5977ae');
70
        $this->assertEquals($expectation, $fromText);
71
    }
72
73
    public function testFromWire(): void
74
    {
75
        $expectation = new NSEC3PARAM();
76
        $expectation->setHashAlgorithm(Algorithms::RSAMD5);
77
        $expectation->setSalt('d9143ec07c5977ae');
78
        $expectation->setIterations(55);
79
        $expectation->setFlags(0);
80
81
        $wireFormat = chr(1).chr(0).pack('n', 55).chr(8).hex2bin('d9143ec07c5977ae');
82
83
        $fromWire = new NSEC3PARAM();
84
        $fromWire->fromWire($wireFormat);
85
        $this->assertEquals($expectation, $fromWire);
86
    }
87
88
    public function testFactory(): void
89
    {
90
        $nsec3param = Factory::NSEC3PARAM(Algorithms::RSAMD5, 0, 55, 'd9143ec07c5977ae');
91
92
        $this->assertEquals(1, $nsec3param->getHashAlgorithm());
93
        $this->assertEquals(0, $nsec3param->getFlags());
94
        $this->assertEquals(55, $nsec3param->getIterations());
95
        $this->assertEquals('d9143ec07c5977ae', $nsec3param->getSalt());
96
    }
97
}
98