1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace MS\PHPMD\Tests\Unit\Symfony2; |
4
|
|
|
|
5
|
|
|
use MS\PHPMD\Rule\Symfony2\ControllerMethodName; |
6
|
|
|
use MS\PHPMD\Tests\Unit\AbstractApplyTest; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class ControllerMethodNameTest |
10
|
|
|
* |
11
|
|
|
* @package MS\PHPMD\Tests\Unit\Symfony2 |
12
|
|
|
*/ |
13
|
|
|
class ControllerMethodNameTest extends AbstractApplyTest |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @covers MS\PHPMD\Rule\Symfony2\ControllerMethodName |
17
|
|
|
*/ |
18
|
|
|
public function testApplyNoConcreteClass() |
19
|
|
|
{ |
20
|
|
|
$node = \Mockery::mock('PHPMD\Node\ClassNode'); |
21
|
|
|
$node->shouldReceive('isAbstract')->andReturn(true); |
22
|
|
|
|
23
|
|
|
$this->assertRule($node, 0); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @covers MS\PHPMD\Rule\Symfony2\ControllerMethodName |
28
|
|
|
*/ |
29
|
|
|
public function testApplyNoController() |
30
|
|
|
{ |
31
|
|
|
$node = \Mockery::mock('PHPMD\Node\ClassNode'); |
32
|
|
|
$node->shouldReceive('isAbstract')->andReturn(false); |
33
|
|
|
$node->shouldReceive('getImage')->andReturn('TestService'); |
34
|
|
|
|
35
|
|
|
$this->assertRule($node, 0); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @covers MS\PHPMD\Rule\Symfony2\ControllerMethodName |
40
|
|
|
*/ |
41
|
|
|
public function testApplyWithDirtyController() |
42
|
|
|
{ |
43
|
|
|
$className = 'TestController'; |
44
|
|
|
$validMethodName = 'testAction'; |
45
|
|
|
$notValidMethodName = 'doSomething'; |
46
|
|
|
|
47
|
|
|
$validMethodNode = \Mockery::mock('PHPMD\Node\MethodNode'); |
48
|
|
|
$validMethodNode->shouldReceive('getImage')->andReturn($validMethodName); |
49
|
|
|
$validMethodNode->shouldReceive('getParentName')->andReturn($className); |
50
|
|
|
$validMethodNode->shouldReceive('getName')->andReturn($validMethodName); |
51
|
|
|
|
52
|
|
|
$notValidMethodNode = \Mockery::mock('PHPMD\Node\MethodNode'); |
53
|
|
|
$notValidMethodNode->shouldReceive('getImage')->andReturn($notValidMethodName); |
54
|
|
|
$notValidMethodNode->shouldReceive('getParentName')->andReturn($className); |
55
|
|
|
$notValidMethodNode->shouldReceive('getName')->andReturn($notValidMethodName); |
56
|
|
|
|
57
|
|
|
$classNode = \Mockery::mock('PHPMD\Node\ClassNode'); |
58
|
|
|
$classNode->shouldReceive('isAbstract')->andReturn(false); |
59
|
|
|
$classNode->shouldReceive('getImage')->andReturn($className); |
60
|
|
|
$classNode->shouldReceive('getMethods')->andReturn([$validMethodNode, $notValidMethodNode]); |
61
|
|
|
|
62
|
|
|
$this->assertRule($classNode, 1); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return ControllerMethodName |
67
|
|
|
*/ |
68
|
|
|
protected function getRule() |
69
|
|
|
{ |
70
|
|
|
$rule = new ControllerMethodName(); |
71
|
|
|
$rule->addProperty('delimiter', ','); |
72
|
|
|
$rule->addProperty('allowedMethodNames', '__construct'); |
73
|
|
|
|
74
|
|
|
return $rule; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|