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
|
|
|
/** |
21
|
|
|
* Test case for the {@link \PHPMD\RuleViolation} class. |
22
|
|
|
* |
23
|
|
|
* @since 0.2.5 |
24
|
|
|
* |
25
|
|
|
* @covers \PHPMD\RuleViolation |
26
|
|
|
*/ |
27
|
|
|
class RuleViolationTest extends AbstractTest |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* testConstructorExtractsClassNameFromGivenType |
31
|
|
|
* |
32
|
|
|
* @return void |
33
|
|
|
*/ |
34
|
|
|
public function testConstructorExtractsClassNameFromGivenType() |
35
|
|
|
{ |
36
|
|
|
$rule = $this->getRuleMock(); |
37
|
|
|
|
38
|
|
|
$node = $this->getClassMock(); |
39
|
|
|
$node->expects($this->once()) |
|
|
|
|
40
|
|
|
->method('getName'); |
41
|
|
|
|
42
|
|
|
new RuleViolation($rule, $node, 'foo'); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* testConstructorExtractsClassNameFromGivenMethod |
47
|
|
|
* |
48
|
|
|
* @return void |
49
|
|
|
*/ |
50
|
|
View Code Duplication |
public function testConstructorExtractsClassNameFromGivenMethod() |
|
|
|
|
51
|
|
|
{ |
52
|
|
|
$rule = $this->getRuleMock(); |
53
|
|
|
|
54
|
|
|
$node = $this->getMethodMock(); |
55
|
|
|
$node->expects($this->once()) |
|
|
|
|
56
|
|
|
->method('getParentName'); |
57
|
|
|
|
58
|
|
|
new RuleViolation($rule, $node, 'foo'); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* testConstructorExtractsMethodNameFromGivenMethod |
63
|
|
|
* |
64
|
|
|
* @return void |
65
|
|
|
*/ |
66
|
|
View Code Duplication |
public function testConstructorExtractsMethodNameFromGivenMethod() |
|
|
|
|
67
|
|
|
{ |
68
|
|
|
$rule = $this->getRuleMock(); |
69
|
|
|
|
70
|
|
|
$node = $this->getMethodMock(); |
71
|
|
|
$node->expects($this->once()) |
|
|
|
|
72
|
|
|
->method('getName'); |
73
|
|
|
|
74
|
|
|
new RuleViolation($rule, $node, 'foo'); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: