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
|
|
|
* Test case for the {@link \PHPMD\Rule\Design\DevelopmentCodeFragment} class. |
24
|
|
|
* |
25
|
|
|
* @link https://github.com/phpmd/phpmd/issues/265 |
26
|
|
|
* @since 2.3.0 |
27
|
|
|
* |
28
|
|
|
* @covers \PHPMD\Rule\Design\DevelopmentCodeFragment |
29
|
|
|
*/ |
30
|
|
|
class DevelopmentCodeFragmentTest extends AbstractTest |
31
|
|
|
{ |
32
|
|
|
/** |
33
|
|
|
* testRuleNotAppliesToMethodWithoutSuspectFunctionCall |
34
|
|
|
* |
35
|
|
|
* @return void |
36
|
|
|
*/ |
37
|
|
|
public function testRuleNotAppliesToMethodWithoutSuspectFunctionCall() |
38
|
|
|
{ |
39
|
|
|
$rule = $this->getRule(); |
40
|
|
|
$rule->setReport($this->getReportMock(0)); |
41
|
|
|
$rule->apply($this->getMethod()); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* testRuleAppliesToMethodWithSuspectFunctionCall |
46
|
|
|
* |
47
|
|
|
* @return void |
48
|
|
|
*/ |
49
|
|
|
public function testRuleAppliesToMethodWithSuspectFunctionCall() |
50
|
|
|
{ |
51
|
|
|
$rule = $this->getRule(); |
52
|
|
|
$rule->setReport($this->getReportMock(1)); |
53
|
|
|
$rule->apply($this->getMethod()); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* testRuleAppliesToMethodWithMultipleSuspectFunctionCall |
58
|
|
|
* |
59
|
|
|
* @return void |
60
|
|
|
*/ |
61
|
|
|
public function testRuleAppliesToMethodWithMultipleSuspectFunctionCall() |
62
|
|
|
{ |
63
|
|
|
$rule = $this->getRule(); |
64
|
|
|
$rule->setReport($this->getReportMock(3)); |
65
|
|
|
$rule->apply($this->getMethod()); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* testRuleNotAppliesToFunctionWithoutSuspectFunctionCall |
70
|
|
|
* |
71
|
|
|
* @return void |
72
|
|
|
*/ |
73
|
|
|
public function testRuleNotAppliesToFunctionWithoutSuspectFunctionCall() |
74
|
|
|
{ |
75
|
|
|
$rule = $this->getRule(); |
76
|
|
|
$rule->setReport($this->getReportMock(0)); |
77
|
|
|
$rule->apply($this->getFunction()); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* testRuleAppliesToFunctionWithSuspectFunctionCall |
82
|
|
|
* |
83
|
|
|
* @return void |
84
|
|
|
*/ |
85
|
|
|
public function testRuleAppliesToFunctionWithSuspectFunctionCall() |
86
|
|
|
{ |
87
|
|
|
$rule = $this->getRule(); |
88
|
|
|
$rule->setReport($this->getReportMock(1)); |
89
|
|
|
$rule->apply($this->getFunction()); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* testRuleAppliesToFunctionWithMultipleSuspectFunctionCall |
94
|
|
|
* |
95
|
|
|
* @return void |
96
|
|
|
*/ |
97
|
|
|
public function testRuleAppliesToFunctionWithMultipleSuspectFunctionCall() |
98
|
|
|
{ |
99
|
|
|
$rule = $this->getRule(); |
100
|
|
|
$rule->setReport($this->getReportMock(3)); |
101
|
|
|
$rule->apply($this->getFunction()); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* testRuleAppliesToMethodWithinNamespace |
106
|
|
|
* |
107
|
|
|
* @return void |
108
|
|
|
*/ |
109
|
|
|
public function testRuleAppliesToMethodWithinNamespace() |
110
|
|
|
{ |
111
|
|
|
$rule = $this->getRule(); |
112
|
|
|
$rule->addProperty('ignore-namespaces', 'true'); |
113
|
|
|
$rule->setReport($this->getReportMock(1)); |
114
|
|
|
$rule->apply($this->getClass()); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* testRuleNotAppliesToMethodWithinNamespaceByDefault |
119
|
|
|
* |
120
|
|
|
* @return void |
121
|
|
|
*/ |
122
|
|
|
public function testRuleNotAppliesToMethodWithinNamespaceByDefault() |
123
|
|
|
{ |
124
|
|
|
$rule = $this->getRule(); |
125
|
|
|
$rule->setReport($this->getReportMock(0)); |
126
|
|
|
$rule->apply($this->getClass()); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Get a configured DevelopmentCodeFragment rule |
131
|
|
|
* @return DevelopmentCodeFragment |
132
|
|
|
*/ |
133
|
|
|
private function getRule() { |
134
|
|
|
$rule = new DevelopmentCodeFragment(); |
135
|
|
|
$rule->addProperty('unwanted-functions', 'var_dump,print_r,debug_zval_dump,debug_print_backtrace'); |
136
|
|
|
$rule->addProperty('ignore-namespaces', 'false'); |
137
|
|
|
return $rule; |
138
|
|
|
} |
139
|
|
|
} |
140
|
|
|
|