|
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 StaticAccessTest extends AbstractTest |
|
23
|
|
|
{ |
|
24
|
|
|
public function testRuleNotAppliesToParentStaticCall() |
|
25
|
|
|
{ |
|
26
|
|
|
$rule = new StaticAccess(); |
|
27
|
|
|
$rule->setReport($this->getReportMock(0)); |
|
28
|
|
|
$rule->apply($this->getMethod()); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function testRuleNotAppliesToSelfStaticCall() |
|
32
|
|
|
{ |
|
33
|
|
|
$rule = new StaticAccess(); |
|
34
|
|
|
$rule->setReport($this->getReportMock(0)); |
|
35
|
|
|
$rule->apply($this->getMethod()); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function testRuleNotAppliesToDynamicMethodCall() |
|
39
|
|
|
{ |
|
40
|
|
|
$rule = new StaticAccess(); |
|
41
|
|
|
$rule->setReport($this->getReportMock(0)); |
|
42
|
|
|
$rule->apply($this->getMethod()); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function testRuleNotAppliesToStaticMethodAccessWhenExcluded() |
|
46
|
|
|
{ |
|
47
|
|
|
$rule = new StaticAccess(); |
|
48
|
|
|
$rule->setReport($this->getReportMock(0)); |
|
49
|
|
|
$rule->addProperty('exceptions', 'Excluded1,Excluded2'); |
|
50
|
|
|
$rule->apply($this->getMethod()); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function testRuleAppliesToStaticMethodAccess() |
|
54
|
|
|
{ |
|
55
|
|
|
$rule = new StaticAccess(); |
|
56
|
|
|
$rule->setReport($this->getReportMock(1)); |
|
57
|
|
|
$rule->apply($this->getMethod()); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function testRuleAppliesToStaticMethodAccessWhenNotAllExcluded() |
|
61
|
|
|
{ |
|
62
|
|
|
$rule = new StaticAccess(); |
|
63
|
|
|
$rule->setReport($this->getReportMock(1)); |
|
64
|
|
|
$rule->addProperty('exceptions', 'Excluded'); |
|
65
|
|
|
$rule->apply($this->getMethod()); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function testRuleNotAppliesToConstantAccess() |
|
69
|
|
|
{ |
|
70
|
|
|
$rule = new StaticAccess(); |
|
71
|
|
|
$rule->setReport($this->getReportMock(0)); |
|
72
|
|
|
$rule->apply($this->getMethod()); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|