Code Duplication    Length = 12-14 lines in 15 locations

tests/php/PHPMD/Regression/ExcessivePublicCountRuleNeverExecutedTicket015Test.php 1 location

@@ 35-48 (lines=14) @@
32
     *
33
     * @return void
34
     */
35
    public function testRuleSetInvokesRuleForClassInstance()
36
    {
37
        $rule = new ExcessivePublicCount();
38
        $rule->addProperty('minimum', 3);
39
40
        $class = $this->getClass();
41
        $class->setMetrics(array('cis' => 4));
42
43
        $ruleSet = new RuleSet();
44
        $ruleSet->addRule($rule);
45
        $ruleSet->setReport($this->getReportMock(1));
46
47
        $ruleSet->apply($class);
48
    }
49
}
50

tests/php/PHPMD/Rule/Controversial/CamelCaseMethodNameTest.php 10 locations

@@ 53-66 (lines=14) @@
50
     *
51
     * @return void
52
     */
53
    public function testRuleDoesApplyForMethodNameWithCapital()
54
    {
55
        // Test method name with capital at the beginning
56
        $method = $this->getMethod();
57
        $report = $this->getReportMock(1);
58
59
        $rule = new CamelCaseMethodName();
60
        $rule->setReport($report);
61
        $rule->addProperty('allow-underscore', 'false');
62
        $rule->addProperty('allow-underscore-test', 'false');
63
        $rule->addProperty('allow-multiple-underscore-test', 'false');
64
65
        $rule->apply($method);
66
    }
67
68
    /**
69
     * Tests that the rule does apply for a method name
@@ 74-87 (lines=14) @@
71
     *
72
     * @return void
73
     */
74
    public function testRuleDoesApplyForMethodNameWithUnderscores()
75
    {
76
        // Test method name with underscores
77
        $method = $this->getMethod();
78
        $report = $this->getReportMock(1);
79
80
        $rule = new CamelCaseMethodName();
81
        $rule->setReport($report);
82
        $rule->addProperty('allow-underscore', 'false');
83
        $rule->addProperty('allow-underscore-test', 'false');
84
        $rule->addProperty('allow-multiple-underscore-test', 'false');
85
86
        $rule->apply($method);
87
    }
88
89
    /**
90
     * Tests that the rule does apply for a valid method name
@@ 95-107 (lines=13) @@
92
     *
93
     * @return void
94
     */
95
    public function testRuleDoesApplyForValidMethodNameWithUnderscoreWhenNotAllowed()
96
    {
97
        $method = $this->getMethod();
98
        $report = $this->getReportMock(1);
99
100
        $rule = new CamelCaseMethodName();
101
        $rule->setReport($report);
102
        $rule->addProperty('allow-underscore', 'false');
103
        $rule->addProperty('allow-underscore-test', 'false');
104
        $rule->addProperty('allow-multiple-underscore-test', 'false');
105
106
        $rule->apply($method);
107
    }
108
109
    /**
110
     * Tests that the rule does not apply for a valid method name
@@ 115-127 (lines=13) @@
112
     *
113
     * @return void
114
     */
115
    public function testRuleDoesNotApplyForValidMethodNameWithUnderscoreWhenAllowed()
116
    {
117
        $method = $this->getMethod();
118
        $report = $this->getReportMock(0);
119
120
        $rule = new CamelCaseMethodName();
121
        $rule->setReport($report);
122
        $rule->addProperty('allow-underscore', 'true');
123
        $rule->addProperty('allow-underscore-test', 'false');
124
        $rule->addProperty('allow-multiple-underscore-test', 'false');
125
126
        $rule->apply($method);
127
    }
128
129
    /**
130
     * Tests that the rule does apply for a valid test method name
@@ 135-147 (lines=13) @@
132
     *
133
     * @return void
134
     */
135
    public function testRuleDoesApplyForTestMethodWithUnderscoreWhenNotAllowed()
136
    {
137
        $method = $this->getMethod();
138
        $report = $this->getReportMock(1);
139
140
        $rule = new CamelCaseMethodName();
141
        $rule->setReport($report);
142
        $rule->addProperty('allow-underscore', 'false');
143
        $rule->addProperty('allow-underscore-test', 'false');
144
        $rule->addProperty('allow-multiple-underscore-test', 'false');
145
146
        $rule->apply($method);
147
    }
148
149
    /**
150
     * Tests that the rule does not apply for a valid test method name
@@ 155-166 (lines=12) @@
152
     *
153
     * @return void
154
     */
155
    public function testRuleDoesNotApplyForTestMethodWithUnderscoreWhenAllowed()
156
    {
157
        $method = $this->getMethod();
158
        $report = $this->getReportMock(0);
159
160
        $rule = new CamelCaseMethodName();
161
        $rule->setReport($report);
162
        $rule->addProperty('allow-underscore', 'false');
163
        $rule->addProperty('allow-underscore-test', 'true');
164
        $rule->addProperty('allow-multiple-underscore-test', 'true');
165
        $rule->apply($method);
166
    }
167
168
    /**
169
     * Tests that the rule does apply for a test method name
@@ 174-185 (lines=12) @@
171
     *
172
     * @return void
173
     */
174
    public function testRuleAppliesToTestMethodWithTwoUnderscoresEvenWhenOneIsAllowed()
175
    {
176
        $method = $this->getMethod();
177
        $report = $this->getReportMock(1);
178
179
        $rule = new CamelCaseMethodName();
180
        $rule->setReport($report);
181
        $rule->addProperty('allow-underscore', 'false');
182
        $rule->addProperty('allow-underscore-test', 'true');
183
        $rule->addProperty('allow-multiple-underscore-test', 'false');
184
        $rule->apply($method);
185
    }
186
187
    /**
188
     * Tests that the rule does apply to for test method names that
@@ 193-204 (lines=12) @@
190
     *
191
     * @return void
192
     */
193
    public function testRuleAppliesToTestMethodWithUnderscoreFollowedByCapital()
194
    {
195
        $method = $this->getMethod();
196
        $report = $this->getReportMock(1);
197
198
        $rule = new CamelCaseMethodName();
199
        $rule->setReport($report);
200
        $rule->addProperty('allow-underscore', 'false');
201
        $rule->addProperty('allow-underscore-test', 'true');
202
        $rule->addProperty('allow-multiple-underscore-test', 'false');
203
        $rule->apply($method);
204
    }
205
206
    /**
207
     * Tests that the rule does apply to for test method names that
@@ 212-223 (lines=12) @@
209
     *
210
     * @return void
211
     */
212
    public function testRuleAppliesToTestMethodWithMultipleUnderscores()
213
    {
214
        $method = $this->getMethod();
215
        $report = $this->getReportMock(0);
216
217
        $rule = new CamelCaseMethodName();
218
        $rule->setReport($report);
219
        $rule->addProperty('allow-underscore', 'false');
220
        $rule->addProperty('allow-underscore-test', 'false');
221
        $rule->addProperty('allow-multiple-underscore-test', 'true');
222
        $rule->apply($method);
223
    }
224
225
    /**
226
     * Tests that the rule does apply to for test method names that
@@ 231-242 (lines=12) @@
228
     *
229
     * @return void
230
     */
231
    public function testRuleDoesNotApplyForTestMethodWithMultipleUnderscoreWhenAllowed()
232
    {
233
        $method = $this->getMethod();
234
        $report = $this->getReportMock(1);
235
236
        $rule = new CamelCaseMethodName();
237
        $rule->setReport($report);
238
        $rule->addProperty('allow-underscore', 'false');
239
        $rule->addProperty('allow-underscore-test', 'false');
240
        $rule->addProperty('allow-multiple-underscore-test', 'false');
241
        $rule->apply($method);
242
    }
243
244
    /**
245
     * Returns the first method found in a source file related to the calling

tests/php/PHPMD/Rule/Naming/ShortVariableTest.php 4 locations

@@ 105-118 (lines=14) @@
102
     *
103
     * @return void
104
     */
105
    public function testRuleAppliesToLocalVariableInMethodWithNameShorterThanThreshold()
106
    {
107
        $rule = new ShortVariable();
108
        $rule->addProperty('minimum', 3);
109
        $rule->addProperty('exceptions', '');
110
        $rule->setReport($this->getReportMock(1));
111
112
        $class = $this->getClass();
113
        $rule->apply($class);
114
115
        foreach ($class->getMethods() as $method) {
116
            $rule->apply($method);
117
        }
118
    }
119
120
    /**
121
     * testRuleNotAppliesToLocalVariableInMethodWithNameEqualToThreshold
@@ 153-166 (lines=14) @@
150
     *
151
     * @return void
152
     */
153
    public function testRuleAppliesToMethodParameterWithNameShorterThanThreshold()
154
    {
155
        $rule = new ShortVariable();
156
        $rule->addProperty('minimum', 3);
157
        $rule->addProperty('exceptions', '');
158
        $rule->setReport($this->getReportMock(1));
159
160
        $class = $this->getClass();
161
        $rule->apply($class);
162
163
        foreach ($class->getMethods() as $method) {
164
            $rule->apply($method);
165
        }
166
    }
167
168
    /**
169
     * testRuleNotAppliesToMethodParameterWithNameLongerThanThreshold
@@ 229-242 (lines=14) @@
226
     *
227
     * @return void
228
     */
229
    public function testRuleAppliesToFieldAndParameterWithNameShorterThanThreshold()
230
    {
231
        $rule = new ShortVariable();
232
        $rule->addProperty('minimum', 3);
233
        $rule->addProperty('exceptions', '');
234
        $rule->setReport($this->getReportMock(2));
235
236
        $class = $this->getClass();
237
        $rule->apply($class);
238
239
        foreach ($class->getMethods() as $method) {
240
            $rule->apply($method);
241
        }
242
    }
243
244
    /**
245
     * testRuleNotAppliesToShortVariableNameAsForLoopIndex
@@ 319-332 (lines=14) @@
316
     *
317
     * @return void
318
     */
319
    public function testRuleAppliesToIdenticalVariablesInDifferentContextsSeveralTimes()
320
    {
321
        $rule = new ShortVariable();
322
        $rule->addProperty('minimum', 3);
323
        $rule->addProperty('exceptions', '');
324
        $rule->setReport($this->getReportMock(2));
325
326
        $class = $this->getClass();
327
        $rule->apply($class);
328
329
        foreach ($class->getMethods() as $method) {
330
            $rule->apply($method);
331
        }
332
    }
333
334
    /**
335
     * testRuleNotAppliesToVariablesFromExceptionsList