|
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\Naming; |
|
19
|
|
|
|
|
20
|
|
|
use PHPMD\AbstractTest; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Test case for the {@link \PHPMD\Rule\Naming\BooleanGetMethodName} rule class. |
|
24
|
|
|
* |
|
25
|
|
|
* @covers PHPMD\Rule\Naming\BooleanGetMethodName |
|
26
|
|
|
*/ |
|
27
|
|
|
class BooleanGetMethodNameTest extends AbstractTest |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* testRuleAppliesToMethodStartingWithGetAndReturningBoolean |
|
31
|
|
|
* |
|
32
|
|
|
* @return void |
|
33
|
|
|
*/ |
|
34
|
|
|
public function testRuleAppliesToMethodStartingWithGetAndReturningBoolean() |
|
35
|
|
|
{ |
|
36
|
|
|
$rule = new BooleanGetMethodName(); |
|
37
|
|
|
$rule->addProperty('checkParameterizedMethods', 'false'); |
|
38
|
|
|
$rule->setReport($this->getReportMock(1)); |
|
39
|
|
|
$rule->apply($this->getMethod()); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* testRuleAppliesToMethodStartingWithGetAndReturningBool |
|
44
|
|
|
* |
|
45
|
|
|
* @return void |
|
46
|
|
|
*/ |
|
47
|
|
|
public function testRuleAppliesToMethodStartingWithGetAndReturningBool() |
|
48
|
|
|
{ |
|
49
|
|
|
$rule = new BooleanGetMethodName(); |
|
50
|
|
|
$rule->addProperty('checkParameterizedMethods', 'false'); |
|
51
|
|
|
$rule->setReport($this->getReportMock(1)); |
|
52
|
|
|
$rule->apply($this->getMethod()); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* testRuleAppliesToPearPrivateMethodStartingWithGetAndReturningBoolean |
|
57
|
|
|
* |
|
58
|
|
|
* @return void |
|
59
|
|
|
*/ |
|
60
|
|
|
public function testRuleAppliesToPearPrivateMethodStartingWithGetAndReturningBoolean() |
|
61
|
|
|
{ |
|
62
|
|
|
$rule = new BooleanGetMethodName(); |
|
63
|
|
|
$rule->addProperty('checkParameterizedMethods', 'false'); |
|
64
|
|
|
$rule->setReport($this->getReportMock(1)); |
|
65
|
|
|
$rule->apply($this->getMethod()); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* testRuleIgnoresParametersWhenNotExplicitConfigured |
|
70
|
|
|
* |
|
71
|
|
|
* @return void |
|
72
|
|
|
*/ |
|
73
|
|
|
public function testRuleIgnoresParametersWhenNotExplicitConfigured() |
|
74
|
|
|
{ |
|
75
|
|
|
$rule = new BooleanGetMethodName(); |
|
76
|
|
|
$rule->addProperty('checkParameterizedMethods', 'false'); |
|
77
|
|
|
$rule->setReport($this->getReportMock(1)); |
|
78
|
|
|
$rule->apply($this->getMethod()); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* testRuleNotAppliesWhenParametersAreExplicitEnabled |
|
83
|
|
|
* |
|
84
|
|
|
* @return void |
|
85
|
|
|
*/ |
|
86
|
|
|
public function testRuleNotAppliesWhenParametersAreExplicitEnabled() |
|
87
|
|
|
{ |
|
88
|
|
|
$rule = new BooleanGetMethodName(); |
|
89
|
|
|
$rule->addProperty('checkParameterizedMethods', 'true'); |
|
90
|
|
|
$rule->setReport($this->getReportMock(0)); |
|
91
|
|
|
|
|
92
|
|
|
$rule->apply($this->getMethod()); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* testRuleNotAppliesToMethodStartingWithIs |
|
97
|
|
|
* |
|
98
|
|
|
* @return void |
|
99
|
|
|
*/ |
|
100
|
|
|
public function testRuleNotAppliesToMethodStartingWithIs() |
|
101
|
|
|
{ |
|
102
|
|
|
$rule = new BooleanGetMethodName(); |
|
103
|
|
|
$rule->addProperty('checkParameterizedMethods', 'false'); |
|
104
|
|
|
$rule->setReport($this->getReportMock(0)); |
|
105
|
|
|
|
|
106
|
|
|
$rule->apply($this->getMethod()); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* testRuleNotAppliesToMethodStartingWithHas |
|
111
|
|
|
* |
|
112
|
|
|
* @return void |
|
113
|
|
|
*/ |
|
114
|
|
|
public function testRuleNotAppliesToMethodStartingWithHas() |
|
115
|
|
|
{ |
|
116
|
|
|
$rule = new BooleanGetMethodName(); |
|
117
|
|
|
$rule->addProperty('checkParameterizedMethods', 'false'); |
|
118
|
|
|
$rule->setReport($this->getReportMock(0)); |
|
119
|
|
|
|
|
120
|
|
|
$rule->apply($this->getMethod()); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* testRuleNotAppliesToMethodWithReturnTypeNotBoolean |
|
125
|
|
|
* |
|
126
|
|
|
* @return void |
|
127
|
|
|
*/ |
|
128
|
|
|
public function testRuleNotAppliesToMethodWithReturnTypeNotBoolean() |
|
129
|
|
|
{ |
|
130
|
|
|
$rule = new BooleanGetMethodName(); |
|
131
|
|
|
$rule->addProperty('checkParameterizedMethods', 'false'); |
|
132
|
|
|
$rule->setReport($this->getReportMock(0)); |
|
133
|
|
|
|
|
134
|
|
|
$rule->apply($this->getMethod()); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* Returns the first method found in a source file related to the calling |
|
139
|
|
|
* test method. |
|
140
|
|
|
* |
|
141
|
|
|
* @return \PHPMD\Node\MethodNode |
|
142
|
|
|
*/ |
|
143
|
|
|
protected function getMethod() |
|
144
|
|
|
{ |
|
145
|
|
|
$methods = $this->getClass()->getMethods(); |
|
146
|
|
|
return reset($methods); |
|
|
|
|
|
|
147
|
|
|
} |
|
148
|
|
|
} |
|
149
|
|
|
|