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; |
19
|
|
|
|
20
|
|
|
use PHPMD\Stubs\RuleStub; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Test case for the {@link \PHPMD\RuleSet} class. |
24
|
|
|
* |
25
|
|
|
* @covers \PHPMD\RuleSet |
26
|
|
|
*/ |
27
|
|
|
class RuleSetTest extends AbstractTest |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* testGetRuleByNameReturnsNullWhenNoMatchingRuleExists |
31
|
|
|
* |
32
|
|
|
* @return void |
33
|
|
|
*/ |
34
|
|
|
public function testGetRuleByNameReturnsNullWhenNoMatchingRuleExists() |
35
|
|
|
{ |
36
|
|
|
$ruleSet = $this->createRuleSetFixture(); |
37
|
|
|
$this->assertNull($ruleSet->getRuleByName(__FUNCTION__)); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* testGetRuleByNameReturnsMatchingRuleInstance |
42
|
|
|
* |
43
|
|
|
* @return void |
44
|
|
|
*/ |
45
|
|
|
public function testGetRuleByNameReturnsMatchingRuleInstance() |
46
|
|
|
{ |
47
|
|
|
$ruleSet = $this->createRuleSetFixture(__FUNCTION__, __CLASS__, __METHOD__); |
48
|
|
|
$rule = $ruleSet->getRuleByName(__CLASS__); |
49
|
|
|
|
50
|
|
|
$this->assertEquals(__CLASS__, $rule->getName()); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* testApplyNotInvokesRuleWhenSuppressAnnotationExists |
55
|
|
|
* |
56
|
|
|
* @return void |
57
|
|
|
*/ |
58
|
|
|
public function testApplyNotInvokesRuleWhenSuppressAnnotationExists() |
59
|
|
|
{ |
60
|
|
|
$ruleSet = $this->createRuleSetFixture(__FUNCTION__); |
61
|
|
|
$ruleSet->setReport($this->getReportMock(0)); |
62
|
|
|
$ruleSet->apply($this->getClass()); |
63
|
|
|
|
64
|
|
|
$this->assertNull($ruleSet->getRuleByName(__FUNCTION__)->node); |
|
|
|
|
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* testApplyInvokesRuleWhenStrictModeIsSet |
69
|
|
|
* |
70
|
|
|
* @return void |
71
|
|
|
*/ |
72
|
|
|
public function testApplyInvokesRuleWhenStrictModeIsSet() |
73
|
|
|
{ |
74
|
|
|
$ruleSet = $this->createRuleSetFixture(__FUNCTION__); |
75
|
|
|
$ruleSet->setReport($this->getReportMock(0)); |
76
|
|
|
$ruleSet->setStrict(); |
77
|
|
|
|
78
|
|
|
$class = $this->getClass(); |
79
|
|
|
$ruleSet->apply($class); |
80
|
|
|
|
81
|
|
|
$this->assertSame($class, $ruleSet->getRuleByName(__FUNCTION__)->node); |
|
|
|
|
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Creates a rule set instance with a variable amount of appended rule |
86
|
|
|
* objects. |
87
|
|
|
* |
88
|
|
|
* @return \PHPMD\AbstractRule |
89
|
|
|
*/ |
90
|
|
|
private function createRuleSetFixture() |
91
|
|
|
{ |
92
|
|
|
$ruleSet = new RuleSet(); |
93
|
|
|
for ($i = 0; $i < func_num_args(); ++$i) { |
94
|
|
|
$rule = new RuleStub(func_get_arg($i)); |
95
|
|
|
|
96
|
|
|
$ruleSet->addRule($rule); |
97
|
|
|
} |
98
|
|
|
return $ruleSet; |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: