1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace MS\PHPMD\Tests\Unit\Test; |
4
|
|
|
|
5
|
|
|
use MS\PHPMD\Rule\Test\MethodNumberOfMocks; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class MethodNumberOfMocksTest |
9
|
|
|
* |
10
|
|
|
* @package MS\PHPMD\Tests\Unit\Test |
11
|
|
|
*/ |
12
|
|
|
class MethodNumberOfMocksTest extends AbstractClassTest |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @covers MS\PHPMD\Rule\Test\MethodNumberOfMocks |
16
|
|
|
* @covers MS\PHPMD\Rule\Test\AbstractMethodNumberOf |
17
|
|
|
* @covers MS\PHPMD\Rule\Test\AbstractTestRule |
18
|
|
|
*/ |
19
|
|
View Code Duplication |
public function testMoreMocks() |
|
|
|
|
20
|
|
|
{ |
21
|
|
|
$methodNode = $this->getMethodNode( |
22
|
|
|
self::CLASS_NAME, |
23
|
|
|
'testBar', |
24
|
|
|
['MethodPostfix' => array_merge( |
25
|
|
|
array_fill(0, 3, $this->getNode('mock')), |
26
|
|
|
array_fill(0, 1, $this->getNode('getMock')) |
27
|
|
|
)] |
28
|
|
|
); |
29
|
|
|
|
30
|
|
|
$node = \Mockery::mock('PHPMD\Node\ClassNode'); |
31
|
|
|
$node->shouldReceive('getImage')->andReturn(self::CLASS_NAME); |
32
|
|
|
$node->shouldReceive('getMethods')->andReturn([$methodNode]); |
33
|
|
|
|
34
|
|
|
$this->assertRule($node, 1); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @return MethodNumberOfMocks |
39
|
|
|
*/ |
40
|
|
|
protected function getRule() |
41
|
|
|
{ |
42
|
|
|
$rule = new MethodNumberOfMocks(); |
43
|
|
|
$rule->addProperty('number', '3'); |
44
|
|
|
$rule->addProperty('names', 'getMock,mock'); |
45
|
|
|
$rule->addProperty('delimiter', ','); |
46
|
|
|
$rule->addProperty('match', '1'); |
47
|
|
|
|
48
|
|
|
return $rule; |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
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.