|
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\ErrorCPD; |
|
60
|
|
|
use PHPCodeBrowser\Tests\AbstractTestCase; |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* ErrorCPDTest |
|
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 ErrorCPDTest extends AbstractTestCase |
|
80
|
|
|
{ |
|
81
|
|
|
/** |
|
82
|
|
|
* The object to test. |
|
83
|
|
|
* |
|
84
|
|
|
* @var ErrorCPD |
|
85
|
|
|
*/ |
|
86
|
|
|
protected $errorCPD; |
|
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-cpd version="phpcpd 1.3.1"> |
|
96
|
|
|
<duplication lines="1" tokens="2"> |
|
97
|
|
|
<file path="/original/file" line="23"/> |
|
98
|
|
|
<file path="/copied/file" line="42"/> |
|
99
|
|
|
<codefragment> |
|
100
|
|
|
echo 'Some code here'; |
|
101
|
|
|
</codefragment> |
|
102
|
|
|
</duplication> |
|
103
|
|
|
</pmd-cpd> |
|
104
|
|
|
HERE; |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* (non-PHPDoc) |
|
108
|
|
|
* |
|
109
|
|
|
* @see tests/cbAbstractTests#setUp() |
|
110
|
|
|
*/ |
|
111
|
|
|
protected function setUp(): void |
|
112
|
|
|
{ |
|
113
|
|
|
parent::setUp(); |
|
114
|
|
|
$issueXML = new IssueXML(); |
|
115
|
|
|
$xml = new DOMDocument('1.0', 'UTF-8'); |
|
116
|
|
|
$xml->loadXML($this->testXml); |
|
117
|
|
|
$issueXML->addXMLFile($xml); |
|
118
|
|
|
$this->errorCPD = new ErrorCPD($issueXML); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* Test getFileList |
|
123
|
|
|
* |
|
124
|
|
|
* @return void |
|
125
|
|
|
*/ |
|
126
|
|
|
public function testGettingFileList(): void |
|
127
|
|
|
{ |
|
128
|
|
|
$expected = [ |
|
129
|
|
|
new File( |
|
130
|
|
|
'/original/file', |
|
131
|
|
|
[ |
|
132
|
|
|
new Issue( |
|
133
|
|
|
'/original/file', |
|
134
|
|
|
23, |
|
135
|
|
|
24, |
|
136
|
|
|
'Duplication', |
|
137
|
|
|
"Copy paste from:\n/copied/file (42)\n (0)", |
|
138
|
|
|
'notice' |
|
139
|
|
|
), |
|
140
|
|
|
] |
|
141
|
|
|
), |
|
142
|
|
|
new File( |
|
143
|
|
|
'/copied/file', |
|
144
|
|
|
[ |
|
145
|
|
|
new Issue( |
|
146
|
|
|
'/copied/file', |
|
147
|
|
|
42, |
|
148
|
|
|
43, |
|
149
|
|
|
'Duplication', |
|
150
|
|
|
"Copy paste from:\n/original/file (23)\n (0)", |
|
151
|
|
|
'notice' |
|
152
|
|
|
), |
|
153
|
|
|
] |
|
154
|
|
|
), |
|
155
|
|
|
]; |
|
156
|
|
|
$actual = $this->errorCPD->getFileList(); |
|
157
|
|
|
static::assertEquals($expected, $actual); |
|
158
|
|
|
} |
|
159
|
|
|
} |
|
160
|
|
|
|