1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace MS\PHPMD\Tests\Unit\Symfony2; |
4
|
|
|
|
5
|
|
|
use MS\PHPMD\Rule\Symfony2\EntityConstants; |
6
|
|
|
use MS\PHPMD\Tests\Unit\AbstractApplyTest; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class EntityConstantsTest |
10
|
|
|
* |
11
|
|
|
* @package MS\PHPMD\Tests\Unit\Symfony2 |
12
|
|
|
*/ |
13
|
|
|
class EntityConstantsTest extends AbstractApplyTest |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @covers MS\PHPMD\Rule\Symfony2\EntityConstants |
17
|
|
|
* @covers MS\PHPMD\Rule\Symfony2\AbstractEntityRule |
18
|
|
|
*/ |
19
|
|
View Code Duplication |
public function testApplyNoEntity() |
|
|
|
|
20
|
|
|
{ |
21
|
|
|
$node = \Mockery::mock('PHPMD\Node\ClassNode'); |
22
|
|
|
$node->shouldReceive('getDocComment')->andReturn(''); |
23
|
|
|
$node->shouldReceive('isAbstract')->andReturn(false); |
24
|
|
|
|
25
|
|
|
$this->assertRule($node, 0); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @covers MS\PHPMD\Rule\Symfony2\EntityConstants |
30
|
|
|
* @covers MS\PHPMD\Rule\Symfony2\AbstractEntityRule |
31
|
|
|
*/ |
32
|
|
|
public function testApplyEntityHasConstants() |
33
|
|
|
{ |
34
|
|
|
$node = \Mockery::mock('PHPMD\Node\ClassNode'); |
35
|
|
|
$node->shouldReceive('getDocComment')->andReturn('* @isEntity'); |
36
|
|
|
$node->shouldReceive('getConstants')->andReturn([1]); |
37
|
|
|
$node->shouldReceive('getName')->andReturn('Entity'); |
38
|
|
|
|
39
|
|
|
$this->assertRule($node, 1); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @return EntityConstants |
44
|
|
|
*/ |
45
|
|
|
protected function getRule() |
46
|
|
|
{ |
47
|
|
|
$rule = new EntityConstants(); |
48
|
|
|
$rule->addProperty('entityRegex', '(\*\s*@\S*Entity)i'); |
49
|
|
|
$rule->addProperty('classIsEntityRegex', '(\*\s*@isEntity)i'); |
50
|
|
|
|
51
|
|
|
return $rule; |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.