1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace MS\PHPMD\Tests\Unit\Test; |
4
|
|
|
|
5
|
|
|
use MS\PHPMD\Rule\Test\MethodNumberOfAsserts; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class MethodNumberOfAssertsTest |
9
|
|
|
* |
10
|
|
|
* @package MS\PHPMD\Tests\Unit\Test |
11
|
|
|
*/ |
12
|
|
|
class MethodNumberOfAssertsTest extends AbstractClassTest |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @covers MS\PHPMD\Rule\Test\MethodNumberOfAsserts |
16
|
|
|
* @covers MS\PHPMD\Rule\Test\AbstractMethodNumberOf |
17
|
|
|
* @covers MS\PHPMD\Rule\Test\AbstractTestRule |
18
|
|
|
*/ |
19
|
|
View Code Duplication |
public function testLessAsserts() |
|
|
|
|
20
|
|
|
{ |
21
|
|
|
$methodNode = $this->getMethodNode( |
22
|
|
|
self::CLASS_NAME, |
23
|
|
|
'testBar', |
24
|
|
|
['MethodPostfix' => array_merge( |
25
|
|
|
array_fill(0, 3, $this->getNode('assertTrue')), |
26
|
|
|
array_fill(0, 5, $this->getNode('if')) |
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, 0); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @covers MS\PHPMD\Rule\Test\MethodNumberOfAsserts |
39
|
|
|
* @covers MS\PHPMD\Rule\Test\AbstractMethodNumberOf |
40
|
|
|
* @covers MS\PHPMD\Rule\Test\AbstractTestRule |
41
|
|
|
*/ |
42
|
|
|
public function testMoreAsserts() |
43
|
|
|
{ |
44
|
|
|
$methodNode = $this->getMethodNode( |
45
|
|
|
self::CLASS_NAME, |
46
|
|
|
'testBar', |
47
|
|
|
['MethodPostfix' => array_fill(0, 6, $this->getNode('assertContains'))] |
48
|
|
|
); |
49
|
|
|
|
50
|
|
|
$node = \Mockery::mock('PHPMD\Node\ClassNode'); |
51
|
|
|
$node->shouldReceive('getImage')->andReturn(self::CLASS_NAME); |
52
|
|
|
$node->shouldReceive('getMethods')->andReturn([$methodNode]); |
53
|
|
|
|
54
|
|
|
$this->assertRule($node, 1); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @return MethodNumberOfAsserts |
59
|
|
|
*/ |
60
|
|
|
protected function getRule() |
61
|
|
|
{ |
62
|
|
|
$rule = new MethodNumberOfAsserts(); |
63
|
|
|
$rule->addProperty('number', '5'); |
64
|
|
|
$rule->addProperty('names', 'assert'); |
65
|
|
|
$rule->addProperty('delimiter', ','); |
66
|
|
|
$rule->addProperty('match', '0'); |
67
|
|
|
|
68
|
|
|
return $rule; |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
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.