AbstractUnitTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 52
c 0
b 0
f 0
wmc 3
lcom 1
cbo 2
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getUnitMock() 0 6 1
A testSiblings() 0 38 2
1
<?php
2
3
namespace Maketok\DataMigration\Unit;
4
5
class AbstractUnitTest extends \PHPUnit_Framework_TestCase
6
{
7
    /**
8
     * @param $code
9
     * @return AbstractUnit
10
     */
11
    public function getUnitMock($code)
12
    {
13
        return $this->getMockBuilder('\Maketok\DataMigration\Unit\AbstractUnit')
14
            ->setConstructorArgs([$code])
15
            ->getMockForAbstractClass();
16
    }
17
18
    public function testSiblings()
19
    {
20
        $uni1 = $this->getUnitMock('tst1');
21
        $uni2 = $this->getUnitMock('tst2');
22
        $uni3 = $this->getUnitMock('tst3');
23
        $uni4 = $this->getUnitMock('tst4');
24
        $uni5 = $this->getUnitMock('tst5');
25
        $uni6 = $this->getUnitMock('tst6');
26
        $uni7 = $this->getUnitMock('tst7');
27
        $uni8 = $this->getUnitMock('tst8'); // orphan on purpose :)
0 ignored issues
show
Unused Code introduced by
$uni8 is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
28
        $uni9 = $this->getUnitMock('tst9');
29
30
        $uni1->addSibling($uni2);
31
        $uni1->addSibling($uni3);
32
        $uni1->addSibling($uni4);
33
        $uni1->addSibling($uni5);
34
        $uni5->addSibling($uni6);
35
        $uni6->addSibling($uni7);
36
        $uni7->addSibling($uni9);
37
38
        $siblings = [
39
            'tst1' => $uni1,
40
            'tst2' => $uni2,
41
            'tst3' => $uni3,
42
            'tst4' => $uni4,
43
            'tst5' => $uni5,
44
            'tst6' => $uni6,
45
            'tst7' => $uni7,
46
            'tst9' => $uni9,
47
        ];
48
49
        /** @var AbstractUnit $unit */
50
        foreach ($siblings as $unit) {
51
            $toCompare = $siblings;
52
            unset($toCompare[$unit->getCode()]);
53
            $this->assertEquals($toCompare, $unit->getSiblings());
54
        }
55
    }
56
}
57