Passed
Pull Request — master (#18)
by Žilvinas
02:40
created

SealTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 105
Duplicated Lines 9.52 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 1
cbo 2
dl 10
loc 105
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetFields() 0 12 1
A testGetFileFieldsWithNonExistingFile() 0 13 1
A testGetAction() 0 5 1
A testGetMethod() 0 5 1
A testCreateResult() 0 5 1
A testHasValidationConstraints() 0 10 1
A getPdfDocument() 10 10 1
B testGetFileFields() 0 31 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
namespace Isign\Tests\Document;
3
4
use Isign\QueryInterface;
5
use Isign\Document\Seal;
6
use Isign\Tests\TestCase;
7
8
class SealTest extends TestCase
9
{
10
    public function testGetFields()
11
    {
12
        $document = $this->getPdfDocument();
13
14
        $method = new Seal('pdf', $document, false);
15
16
        $result = $method->getFields();
17
18
        $this->assertSame('pdf', $result['type']);
19
        $this->assertSame($document, $result['pdf']);
20
        $this->assertSame(false, $result['timestamp']);
21
    }
22
23
    public function testGetFileFields()
24
    {
25
        $method = new Seal(
26
            'asic',
27
            [
28
                'files' => [
29
                    [
30
                        'name' => 'filename.pdf',
31
                        'digest' => 'some digest',
32
                        'content' => 'some content'
33
                    ],
34
                    __DIR__.'/../data/document.pdf'
35
                ]
36
            ],
37
            false
38
        );
39
        $result = $method->getFields();
40
41
        $this->assertArrayHasKey('asic', $result);
42
        $this->assertArrayHasKey('files', $result['asic']);
43
        $this->assertArrayHasKey(0, $result['asic']['files']);
44
        $file0 = $result['asic']['files'][0];
45
        $this->assertArrayHasKey('name', $file0);
46
        $this->assertArrayHasKey('digest', $file0);
47
        $this->assertArrayHasKey('content', $file0);
48
        $this->assertArrayHasKey(1, $result['asic']['files']);
49
        $file1 = $result['asic']['files'][1];
50
        $this->assertArrayHasKey('name', $file1);
51
        $this->assertArrayHasKey('digest', $file1);
52
        $this->assertArrayHasKey('content', $file1);
53
    }
54
55
    /**
56
     * @expectedException \RuntimeException
57
     * @expectedExceptionMessage File "" does not exist
58
     */
59
    public function testGetFileFieldsWithNonExistingFile()
60
    {
61
        $method = new Seal(
62
            'pdf',
63
            [
64
                'files' => [
65
                    ''
66
                ]
67
            ],
68
            false
69
        );
70
        $method->getFields();
71
    }
72
73
    public function testGetAction()
74
    {
75
        $method = new Seal('', [], false);
76
        $this->assertSame('seal', $method->getAction());
77
    }
78
79
    public function testGetMethod()
80
    {
81
        $method = new Seal('', [], false);
82
        $this->assertSame(QueryInterface::POST, $method->getMethod());
83
    }
84
85
    public function testCreateResult()
86
    {
87
        $method = new Seal('', [], false);
88
        $this->assertInstanceOf('Isign\Document\SealResult', $method->createResult());
89
    }
90
91
    public function testHasValidationConstraints()
92
    {
93
        $method = new Seal('', [], false);
94
        $collection = $method->getValidationConstraints();
95
96
        $this->assertInstanceOf(
97
            'Symfony\Component\Validator\Constraints\Collection',
98
            $collection
99
        );
100
    }
101
102 View Code Duplication
    private function getPdfDocument()
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...
103
    {
104
        return [
105
            'signing_purpose' => '',
106
            'contact' => '',
107
            'reason' => '',
108
            'location' => '',
109
            'files' => [],
110
        ];
111
    }
112
}
113