1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of PHP Mess Detector. |
4
|
|
|
* |
5
|
|
|
* Copyright (c) Manuel Pichler <[email protected]>. |
6
|
|
|
* All rights reserved. |
7
|
|
|
* |
8
|
|
|
* Licensed under BSD License |
9
|
|
|
* For full copyright and license information, please see the LICENSE file. |
10
|
|
|
* Redistributions of files must retain the above copyright notice. |
11
|
|
|
* |
12
|
|
|
* @author Manuel Pichler <[email protected]> |
13
|
|
|
* @copyright Manuel Pichler. All rights reserved. |
14
|
|
|
* @license https://opensource.org/licenses/bsd-license.php BSD License |
15
|
|
|
* @link http://phpmd.org/ |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
namespace PHPMD\Rule\Design; |
19
|
|
|
|
20
|
|
|
use PHPMD\AbstractTest; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Count In Loop Expression Test |
24
|
|
|
* |
25
|
|
|
* @author Kamil Szymanski <[email protected]> |
26
|
|
|
*/ |
27
|
|
View Code Duplication |
class CountInLoopExpressionTest extends AbstractTest |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* testRuleAppliesToAllTypesOfLoops |
31
|
|
|
* |
32
|
|
|
* @return void |
33
|
|
|
*/ |
34
|
|
|
public function testRuleAppliesToAllTypesOfLoops() |
35
|
|
|
{ |
36
|
|
|
$rule = new CountInLoopExpression(); |
37
|
|
|
$rule->setReport($this->getReportMock(3)); |
38
|
|
|
$rule->apply($this->getMethod()); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* testRuleNotApplyToExpressionElsewhere |
43
|
|
|
* |
44
|
|
|
* @return void |
45
|
|
|
*/ |
46
|
|
|
public function testRuleNotApplyToExpressionElsewhere() |
47
|
|
|
{ |
48
|
|
|
$rule = new CountInLoopExpression(); |
49
|
|
|
$rule->setReport($this->getReportMock(0)); |
50
|
|
|
$rule->apply($this->getMethod()); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* testRuleApplyToNestedLoops |
55
|
|
|
* |
56
|
|
|
* @return void |
57
|
|
|
*/ |
58
|
|
|
public function testRuleApplyToNestedLoops() |
59
|
|
|
{ |
60
|
|
|
$rule = new CountInLoopExpression(); |
61
|
|
|
$rule->setReport($this->getReportMock(8)); |
62
|
|
|
$rule->apply($this->getFunction()); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* testMutedRuleAtClassLevel |
67
|
|
|
* |
68
|
|
|
* @return void |
69
|
|
|
*/ |
70
|
|
|
public function testMutedRuleAtClassLevel() |
71
|
|
|
{ |
72
|
|
|
$rule = new CountInLoopExpression(); |
73
|
|
|
$rule->setReport($this->getReportMock(0)); |
74
|
|
|
$rule->apply($this->getClass()); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* testMutedRuleAtMethodLevel |
79
|
|
|
* |
80
|
|
|
* @return void |
81
|
|
|
*/ |
82
|
|
|
public function testMutedRuleAtMethodLevel() |
83
|
|
|
{ |
84
|
|
|
$rule = new CountInLoopExpression(); |
85
|
|
|
$rule->setReport($this->getReportMock(0)); |
86
|
|
|
$rule->apply($this->getClass()); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|