DiffTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A assertArrayInterfaces() 0 6 1
A setUp() 0 4 1
A testDiff() 0 40 2
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
18
/**
19
 * DiffTest
20
 *
21
 * @author Matteo Giachino <[email protected]>
22
 */
23
24
class DiffTest extends TestCase
25
{
26
    public function setUp(): void
27
    {
28
        $this->initRepository();
29
    }
30
31
    public function testDiff(): void
32
    {
33
        $this->getRepository()->init();
34
        $this->addFile('foo', null, "content line 1\ncontent line 2\ncontent line 3");
35
        $this->getRepository()->commit('commit1', true);
36
        $this->addFile('foo', null, "content line 1\ncontent line 2 changed");
37
        $this->getRepository()->commit('commit2', true);
38
        $commit = $this->getRepository()->getCommit();
39
40
        $diff = Diff::create($this->getRepository(), $commit);
41
42
        $this->assertInstanceOf('\GitElephant\Objects\Diff\Diff', $diff);
43
        $this->assertArrayInterfaces($diff);
44
        $this->assertCount(1, $diff);
45
        $object = $diff[0];
46
        $this->assertInstanceOf('\GitElephant\Objects\Diff\DiffObject', $object);
47
        $this->assertArrayInterfaces($object);
48
        $this->assertCount(1, $object);
49
        $chunk = $object[0];
50
        $this->assertInstanceOf('\GitElephant\Objects\Diff\DiffChunk', $chunk);
51
        $this->assertArrayInterfaces($chunk);
52
        $this->assertCount(5, $chunk);
53
54
        foreach ($chunk as $chunkLine) {
55
            $this->assertInstanceOf('\GitElephant\Objects\Diff\DiffChunkLine', $chunkLine);
56
        }
57
58
        $this->assertInstanceOf('\GitElephant\Objects\Diff\DiffChunkLineUnchanged', $chunk[0]);
59
        $this->assertInstanceOf('\GitElephant\Objects\Diff\DiffChunkLineChanged', $chunk[1]);
60
        $this->assertInstanceOf('\GitElephant\Objects\Diff\DiffChunkLineDeleted', $chunk[2]);
61
        $this->assertInstanceOf('\GitElephant\Objects\Diff\DiffChunkLineAdded', $chunk[3]);
62
        $this->assertInstanceOf('\GitElephant\Objects\Diff\DiffChunkLineUnchanged', $chunk[4]);
63
        
64
        $this->assertEquals(1, $chunk[0]->getOriginNumber());
65
        $this->assertEquals(1, $chunk[0]->getDestNumber());
66
        $this->assertEquals(2, $chunk[1]->getNumber());
67
        $this->assertEquals(2, $chunk[1]->getOriginNumber());
68
        $this->assertEquals(3, $chunk[4]->getDestNumber());
69
        $this->assertEquals(4, $chunk[4]->getOriginNumber());
70
    }
71
72
    private function assertArrayInterfaces($obj): void
73
    {
74
        $this->assertInstanceOf('\Iterator', $obj);
75
        $this->assertInstanceOf('\Countable', $obj);
76
        $this->assertInstanceOf('\ArrayAccess', $obj);
77
    }
78
}
79