MethodNumberOfAssertsTest::testMoreAsserts()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 2
Metric Value
c 3
b 1
f 2
dl 0
loc 14
rs 9.4285
cc 1
eloc 9
nc 1
nop 0
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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