Completed
Push — develop ( 5f7df1...9cb564 )
by Matteo
10s
created

DiffTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5
Metric Value
wmc 4
lcom 1
cbo 5
dl 0
loc 44
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
B testDiff() 0 29 2
A assertArrayInterfaces() 0 6 1
1
<?php
2
3
/**
4
 * This file is part of the GitElephant package.
5
 *
6
 * (c) Matteo Giachino <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * Just for fun...
12
 */
13
14
namespace GitElephant\Objects\Diff;
15
16
use \GitElephant\TestCase;
17
use \GitElephant\Objects\Diff\Diff,
18
    \GitElephant\Objects\Diff\DiffObject,
19
    \GitElephant\Objects\Diff\DiffChunk,
20
    \GitElephant\Objects\Diff\DiffChunkLine,
21
    \GitElephant\Objects\Diff\DiffChunkLineAdded,
22
    \GitElephant\Objects\Diff\DiffChunkLineDeleted,
23
    \GitElephant\Objects\Diff\DiffChunkLineUnchanged,
24
    \GitElephant\Objects\Commit;
25
26
use \GitElephant\Command\MainCommand,
27
    \GitElephant\Command\DiffCommand,
28
    \GitElephant\Command\ShowCommand;
29
30
/**
31
 * DiffTest
32
 *
33
 * @author Matteo Giachino <[email protected]>
34
 */
35
36
class DiffTest extends TestCase
37
{
38
    public function setUp()
39
    {
40
        $this->initRepository();
41
    }
42
43
    public function testDiff()
44
    {
45
        $mainCommand = new MainCommand();
0 ignored issues
show
Unused Code introduced by
$mainCommand 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...
46
        $diffCommand = new DiffCommand();
0 ignored issues
show
Unused Code introduced by
$diffCommand 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...
47
48
        $this->getRepository()->init();
49
        $this->addFile('foo', null, "content line 1\ncontent line 2\ncontent line 3");
50
        $this->getRepository()->commit('commit1', true);
51
        $this->addFile('foo', null, "content line 1\ncontent line 2 changed");
52
        $this->getRepository()->commit('commit2', true);
53
        $commit = $this->getRepository()->getCommit();
54
55
        $diff = Diff::create($this->getRepository(), $commit);
56
57
        $this->assertInstanceOf('\GitElephant\Objects\Diff\Diff', $diff);
58
        $this->assertArrayInterfaces($diff);
59
        $this->assertCount(1, $diff);
60
        $object = $diff[0];
61
        $this->assertInstanceOf('\GitElephant\Objects\Diff\DiffObject', $object);
62
        $this->assertArrayInterfaces($object);
63
        $this->assertCount(1, $object);
64
        $chunk = $object[0];
65
        $this->assertInstanceOf('\GitElephant\Objects\Diff\DiffChunk', $chunk);
66
        $this->assertArrayInterfaces($chunk);
67
        $this->assertCount(5, $chunk);
68
        foreach ($chunk as $chunkLine) {
69
            $this->assertInstanceOf('\GitElephant\Objects\Diff\DiffChunkLine', $chunkLine);
70
        }
71
    }
72
73
    private function assertArrayInterfaces($obj)
74
    {
75
        $this->assertInstanceOf('\Iterator', $obj);
76
        $this->assertInstanceOf('\Countable', $obj);
77
        $this->assertInstanceOf('\ArrayAccess', $obj);
78
    }
79
}
80