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 cases for LongClassName. |
24
|
|
|
* |
25
|
|
|
* @coversDefaultClass \PHPMD\Rule\Naming\LongClassName |
26
|
|
|
*/ |
27
|
|
|
class LongClassNameTest extends AbstractTest |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* Tests that the rule does not apply to class name length (43) below threshold (44) |
31
|
|
|
* |
32
|
|
|
* @return void |
33
|
|
|
*/ |
34
|
|
|
public function testRuleNotAppliesToClassNameBelowThreshold() |
35
|
|
|
{ |
36
|
|
|
$rule = new LongClassName(); |
37
|
|
|
$rule->addProperty('maximum', 44); |
38
|
|
|
$rule->setReport($this->getReportWithNoViolation()); |
39
|
|
|
$rule->apply($this->getClass()); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Tests that the rule applies to class name length (40) below threshold (39) |
44
|
|
|
* |
45
|
|
|
* @return void |
46
|
|
|
*/ |
47
|
|
|
public function testRuleAppliesToClassNameAboveThreshold() |
48
|
|
|
{ |
49
|
|
|
$rule = new LongClassName(); |
50
|
|
|
$rule->addProperty('maximum', 39); |
51
|
|
|
$rule->setReport($this->getReportWithOneViolation()); |
52
|
|
|
$rule->apply($this->getClass()); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Tests that the rule does not apply to interface name length (47) below threshold (47) |
57
|
|
|
* |
58
|
|
|
* @return void |
59
|
|
|
*/ |
60
|
|
|
public function testRuleNotAppliesToInterfaceNameBelowThreshold() |
61
|
|
|
{ |
62
|
|
|
$rule = new LongClassName(); |
63
|
|
|
$rule->addProperty('maximum', 47); |
64
|
|
|
$rule->setReport($this->getReportWithNoViolation()); |
65
|
|
|
$rule->apply($this->getInterface()); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Tests that the rule applies to class name length (44) above threshold (43) |
70
|
|
|
* |
71
|
|
|
* @return void |
72
|
|
|
*/ |
73
|
|
View Code Duplication |
public function testRuleAppliesToInterfaceNameAboveThreshold() |
74
|
|
|
{ |
75
|
|
|
$rule = new LongClassName(); |
76
|
|
|
$rule->addProperty('maximum', 43); |
77
|
|
|
$rule->setReport($this->getReportWithOneViolation()); |
78
|
|
|
$rule->apply($this->getInterface()); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Tests that the rule does not apply to class name length (69) below threshold (60) |
83
|
|
|
* with configured suffix length (9) |
84
|
|
|
* |
85
|
|
|
* @return void |
86
|
|
|
*/ |
87
|
|
|
public function testRuleNotAppliesToClassNameLengthWithSuffixSubtractedBelowThreshold() |
88
|
|
|
{ |
89
|
|
|
$rule = new LongClassName(); |
90
|
|
|
$rule->addProperty('maximum', 60); |
91
|
|
|
$rule->addProperty('subtract-suffixes', 'Threshold'); |
92
|
|
|
$rule->setReport($this->getReportWithNoViolation()); |
93
|
|
|
$rule->apply($this->getClass()); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Tests that the rule applies to class name length (66) above threshold (56) with configured suffix length (9) |
98
|
|
|
* |
99
|
|
|
* @return void |
100
|
|
|
*/ |
101
|
|
|
public function testRuleAppliesToClassNameLengthWithSuffixSubtractedAboveThreshold() |
102
|
|
|
{ |
103
|
|
|
$rule = new LongClassName(); |
104
|
|
|
$rule->addProperty('maximum', 56); |
105
|
|
|
$rule->addProperty('subtract-suffixes', 'Threshold'); |
106
|
|
|
$rule->setReport($this->getReportWithOneViolation()); |
107
|
|
|
$rule->apply($this->getClass()); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Tests that the rule does not apply to class name length (55) below threshold (54) |
112
|
|
|
* not matching configured suffix length (9) |
113
|
|
|
* |
114
|
|
|
* @return void |
115
|
|
|
*/ |
116
|
|
|
public function testRuleAppliesToClassNameLengthWithoutSuffixSubtracted() |
117
|
|
|
{ |
118
|
|
|
$rule = new LongClassName(); |
119
|
|
|
$rule->addProperty('maximum', 54); |
120
|
|
|
$rule->addProperty('subtract-suffixes', 'Threshold'); |
121
|
|
|
$rule->setReport($this->getReportWithOneViolation()); |
122
|
|
|
$rule->apply($this->getClass()); |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|