|
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(); |
|
|
|
|
|
|
46
|
|
|
$diffCommand = new DiffCommand(); |
|
|
|
|
|
|
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
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.