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\CleanCode; |
19
|
|
|
|
20
|
|
|
use PHPMD\AbstractTest; |
21
|
|
|
|
22
|
|
|
class IfStatementAssignmentTest extends AbstractTest |
23
|
|
|
{ |
24
|
|
|
public function testRuleNotAppliesInsideClosure() |
25
|
|
|
{ |
26
|
|
|
$rule = new IfStatementAssignment(); |
27
|
|
|
$rule->setReport($this->getReportMock(0)); |
28
|
|
|
$rule->apply($this->getMethod()); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function testRuleNotAppliesInsideClosureCallbacks() |
32
|
|
|
{ |
33
|
|
|
$rule = new IfStatementAssignment(); |
34
|
|
|
$rule->setReport($this->getReportMock(0)); |
35
|
|
|
$rule->apply($this->getMethod()); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testRuleNotAppliesToIfsWithoutAssignment() |
39
|
|
|
{ |
40
|
|
|
$rule = new IfStatementAssignment(); |
41
|
|
|
$rule->setReport($this->getReportMock(0)); |
42
|
|
|
$rule->apply($this->getMethod()); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function testRuleNotAppliesToIfsWithConditionsOnly() |
46
|
|
|
{ |
47
|
|
|
$rule = new IfStatementAssignment(); |
48
|
|
|
$rule->setReport($this->getReportMock(0)); |
49
|
|
|
$rule->apply($this->getMethod()); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function testRuleNotAppliesToLogicalOperators() |
53
|
|
|
{ |
54
|
|
|
$rule = new IfStatementAssignment(); |
55
|
|
|
$rule->setReport($this->getReportMock(0)); |
56
|
|
|
$rule->apply($this->getMethod()); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function testRuleWorksCorrectlyWhenExpressionContainsMath() |
60
|
|
|
{ |
61
|
|
|
$rule = new IfStatementAssignment(); |
62
|
|
|
$rule->setReport($this->getReportMock(3)); |
63
|
|
|
$rule->apply($this->getMethod()); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function testRuleAppliesToFunctions() |
67
|
|
|
{ |
68
|
|
|
$rule = new IfStatementAssignment(); |
69
|
|
|
$rule->setReport($this->getReportMock(1)); |
70
|
|
|
$rule->apply($this->getFunction()); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function testRuleAppliesMultipleIfConditions() |
74
|
|
|
{ |
75
|
|
|
$rule = new IfStatementAssignment(); |
76
|
|
|
$rule->setReport($this->getReportMock(1)); |
77
|
|
|
$rule->apply($this->getFunction()); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function testRuleAppliesToMultilevelIfConditions() |
81
|
|
|
{ |
82
|
|
|
$rule = new IfStatementAssignment(); |
83
|
|
|
$rule->setReport($this->getReportMock(6)); |
84
|
|
|
$rule->apply($this->getFunction()); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function testRuleAppliesMultipleTimesInOneIfCondition() |
88
|
|
|
{ |
89
|
|
|
$rule = new IfStatementAssignment(); |
90
|
|
|
$rule->setReport($this->getReportMock(3)); |
91
|
|
|
$rule->apply($this->getFunction()); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|