|
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; |
|
15
|
|
|
|
|
16
|
|
|
use GitElephant\TestCase; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* LogRangeTest |
|
20
|
|
|
* |
|
21
|
|
|
* @author Matteo Giachino <[email protected]> |
|
22
|
|
|
*/ |
|
23
|
|
|
class LogRangeTest extends TestCase |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @var Commit |
|
27
|
|
|
*/ |
|
28
|
|
|
private $firstCommit; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var Commit |
|
32
|
|
|
*/ |
|
33
|
|
|
private $secondCommit; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var Commit |
|
37
|
|
|
*/ |
|
38
|
|
|
private $lastCommit; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* setUp |
|
42
|
|
|
*/ |
|
43
|
|
|
public function setUp(): void |
|
44
|
|
|
{ |
|
45
|
|
|
$this->initRepository(null, 0); |
|
46
|
|
|
$this->initRepository(null, 1); |
|
47
|
|
|
$r1 = $this->getRepository(0); |
|
48
|
|
|
$r1->init(); |
|
49
|
|
|
|
|
50
|
|
|
for ($i = 0; $i < 10; $i++) { |
|
51
|
|
|
$this->addFile('test file ' . $i, null, null, $r1); |
|
52
|
|
|
$this->getRepository(0)->commit('test commit index:' . $i, true); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
$log = $this->getRepository(0)->getLog(); |
|
56
|
|
|
$this->firstCommit = $log[9]; |
|
57
|
|
|
$this->lastCommit = $log[0]; |
|
58
|
|
|
$this->secondCommit = $log[8]; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function testCreateFromCommand(): void |
|
62
|
|
|
{ |
|
63
|
|
|
$logRange = new LogRange($this->getRepository(0), $this->firstCommit, $this->lastCommit); |
|
64
|
|
|
$this->assertInstanceOf('\ArrayAccess', $logRange); |
|
65
|
|
|
$this->assertInstanceOf('\Countable', $logRange); |
|
66
|
|
|
$this->assertInstanceOf('\Iterator', $logRange); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function testToArray(): void |
|
70
|
|
|
{ |
|
71
|
|
|
$logRange = new LogRange($this->getRepository(0), $this->firstCommit, $this->lastCommit); |
|
72
|
|
|
$this->assertIsArray($logRange->toArray()); |
|
73
|
|
|
$this->assertCount(9, $logRange->toArray()); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function testIndex(): void |
|
77
|
|
|
{ |
|
78
|
|
|
$logRange = new LogRange($this->getRepository(0), $this->firstCommit, $this->lastCommit); |
|
79
|
|
|
$this->assertEquals($this->lastCommit, $logRange->index(0)); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function testArrayAccess(): void |
|
83
|
|
|
{ |
|
84
|
|
|
$logRange = new LogRange($this->getRepository(0), $this->firstCommit, $this->lastCommit); |
|
85
|
|
|
$this->assertEquals($this->lastCommit, $logRange->first()); |
|
86
|
|
|
$this->assertEquals($this->secondCommit, $logRange->last()); |
|
87
|
|
|
$this->assertEquals($this->lastCommit, $logRange[0]); |
|
88
|
|
|
$this->assertEquals($this->secondCommit, $logRange[8]); |
|
89
|
|
|
$this->assertTrue(isset($logRange[0])); |
|
90
|
|
|
foreach ($logRange as $key => $commit) { |
|
91
|
|
|
$this->assertInstanceOf('GitElephant\Objects\Commit', $commit); |
|
92
|
|
|
$this->assertIsInt($key); |
|
93
|
|
|
} |
|
94
|
|
|
$r = $this->getRepository(1); |
|
95
|
|
|
$logRange->setRepository($r); |
|
96
|
|
|
$this->assertEquals($r, $logRange->getRepository()); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* testExceptionOnSet |
|
101
|
|
|
*/ |
|
102
|
|
|
public function testExceptionOnSet(): void |
|
103
|
|
|
{ |
|
104
|
|
|
$this->expectException(\RuntimeException::class); |
|
105
|
|
|
$logRange = new LogRange($this->getRepository(0), $this->firstCommit, $this->lastCommit); |
|
106
|
|
|
$logRange[9] = 'test'; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* testExceptionOnUnSet |
|
111
|
|
|
*/ |
|
112
|
|
|
public function testExceptionOnUnset(): void |
|
113
|
|
|
{ |
|
114
|
|
|
$this->expectException(\RuntimeException::class); |
|
115
|
|
|
$logRange = new LogRange($this->getRepository(0), $this->firstCommit, $this->lastCommit); |
|
116
|
|
|
unset($logRange[0]); |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
|