ErrorPMDTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 107
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 62
c 0
b 0
f 0
dl 0
loc 107
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testGettingFileList() 0 44 1
A setUp() 0 8 1
1
<?php
2
3
/**
4
 * Test case
5
 *
6
 * Copyright (c) 2007-2010, Mayflower GmbH
7
 * All rights reserved.
8
 *
9
 * Redistribution and use in source and binary forms, with or without
10
 * modification, are permitted provided that the following conditions
11
 * are met:
12
 *
13
 *   * Redistributions of source code must retain the above copyright
14
 *     notice, this list of conditions and the following disclaimer.
15
 *
16
 *   * Redistributions in binary form must reproduce the above copyright
17
 *     notice, this list of conditions and the following disclaimer in
18
 *     the documentation and/or other materials provided with the
19
 *     distribution.
20
 *
21
 *   * Neither the name of Mayflower GmbH nor the names of his
22
 *     contributors may be used to endorse or promote products derived
23
 *     from this software without specific prior written permission.
24
 *
25
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
28
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
29
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36
 * POSSIBILITY OF SUCH DAMAGE.
37
 *
38
 * @category PHP_CodeBrowser
39
 *
40
 * @author Simon Kohlmeyer <[email protected]
41
 *
42
 * @copyright 2007-2010 Mayflower GmbH
43
 *
44
 * @license http://www.opensource.org/licenses/bsd-license.php  BSD License
45
 *
46
 * @version SVN: $Id$
47
 *
48
 * @link http://www.phpunit.de/
49
 *
50
 * @since File available since  0.9.0
51
 */
52
53
namespace PHPCodeBrowser\Tests\Plugins;
54
55
use DOMDocument;
56
use PHPCodeBrowser\File;
57
use PHPCodeBrowser\Issue;
58
use PHPCodeBrowser\IssueXML;
59
use PHPCodeBrowser\Plugins\ErrorPMD;
60
use PHPCodeBrowser\Tests\AbstractTestCase;
61
62
/**
63
 * ErrorPMDTest
64
 *
65
 * @category PHP_CodeBrowser
66
 *
67
 * @author Simon Kohlmeyer <[email protected]>
68
 *
69
 * @copyright 2007-2010 Mayflower GmbH
70
 *
71
 * @license http://www.opensource.org/licenses/bsd-license.php  BSD License
72
 *
73
 * @version Release: @package_version@
74
 *
75
 * @link http://www.phpunit.de/
76
 *
77
 * @since Class available since  0.9.0
78
 */
79
class ErrorPMDTest extends AbstractTestCase
80
{
81
    /**
82
     * The object to test.
83
     *
84
     * @var ErrorPMD
85
     */
86
    protected $errorPmd;
87
88
    /**
89
     * The xml string to test the plugin against.
90
     *
91
     * @var string
92
     */
93
    protected $testXml = <<<HERE
94
<?xml version="1.0" encoding="UTF-8" ?>
95
<pmd version="0.2.6" timestamp="2010-07-17T02:38:00-07:00">
96
  <file name="/some/file">
97
    <violation beginline="3"
98
               endline="4"
99
               rule="Rule1"
100
               ruleset="Ruleset 1"
101
               priority="1">Description 1</violation>
102
    <violation beginline="5"
103
               endline="5"
104
               rule="Rule2"
105
               ruleset="Ruleset 1"
106
               class="SomeClass"
107
               method="someMethod"
108
               priority="3">Description 2</violation>
109
  </file>
110
  <file name="/other/file">
111
    <violation beginline="15"
112
               endline="15"
113
               rule="The third rule"
114
               ruleset="Ruleset two"
115
               priority="3">Description 3</violation>
116
  </file>
117
  <file name="/has/no/violation">
118
  </file>
119
</pmd>
120
HERE;
121
122
    /**
123
     * (non-PHPDoc)
124
     *
125
     * @see tests/cbAbstractTests#setUp()
126
     */
127
    protected function setUp(): void
128
    {
129
        parent::setUp();
130
        $issueXML = new IssueXML();
131
        $xml      = new DOMDocument('1.0', 'UTF-8');
132
        $xml->loadXML($this->testXml);
133
        $issueXML->addXMLFile($xml);
134
        $this->errorPmd = new ErrorPMD($issueXML);
135
    }
136
137
    /**
138
     * Test getFileList
139
     *
140
     * @return void
141
     */
142
    public function testGettingFileList(): void
143
    {
144
        $expected = [
145
            new File(
146
                '/some/file',
147
                [
148
                    new Issue(
149
                        '/some/file',
150
                        3,
151
                        4,
152
                        'PMD',
153
                        'Description 1',
154
                        'error'
155
                    ),
156
                    new Issue(
157
                        '/some/file',
158
                        5,
159
                        5,
160
                        'PMD',
161
                        'Description 2',
162
                        'error'
163
                    ),
164
                ]
165
            ),
166
            new File(
167
                '/other/file',
168
                [
169
                    new Issue(
170
                        '/other/file',
171
                        15,
172
                        15,
173
                        'PMD',
174
                        'Description 3',
175
                        'error'
176
                    ),
177
                ]
178
            ),
179
            new File(
180
                '/has/no/violation',
181
                []
182
            ),
183
        ];
184
        $actual   = $this->errorPmd->getFileList();
185
        static::assertEquals($expected, $actual);
186
    }
187
}
188