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
|
|
|
use \GitElephant\Objects\Log; |
18
|
|
|
use \GitElephant\Command\LogCommand; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* LogTest |
22
|
|
|
* |
23
|
|
|
* @author Mathias Geat <[email protected]> |
24
|
|
|
*/ |
25
|
|
|
class LogTest extends TestCase |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* setUp |
29
|
|
|
*/ |
30
|
|
|
public function setUp() |
31
|
|
|
{ |
32
|
|
|
$this->getRepository()->init(); |
33
|
|
|
|
34
|
|
|
for ($i = 0; $i < 10; $i++) { |
35
|
|
|
$this->addFile('test file ' . $i); |
36
|
|
|
$this->getRepository()->commit('test commit index:' . $i, true); |
37
|
|
|
} |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* testLogCountable |
42
|
|
|
*/ |
43
|
|
|
public function testLogCountable() |
44
|
|
|
{ |
45
|
|
|
$log = $this->getRepository()->getLog(); |
46
|
|
|
$this->assertEquals($log->count(), count($log)); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* parents created by log |
51
|
|
|
*/ |
52
|
|
|
public function testParents() |
53
|
|
|
{ |
54
|
|
|
$log = $this->getRepository()->getLog(); |
55
|
|
|
$lastCommit = $this->repository->getCommit(); |
56
|
|
|
$lastLogCommit = $log[0]; |
57
|
|
|
$this->assertEquals($lastCommit->getParents(), $lastLogCommit->getParents()); |
58
|
|
|
Branch::create($this->repository, 'new-branch'); |
59
|
|
|
$this->getRepository()->checkout('new-branch'); |
60
|
|
|
$this->addFile('another file'); |
61
|
|
|
$this->repository->commit('another commit', true); |
62
|
|
|
$lastCommitOtherBranch = $this->getRepository()->getCommit(); |
63
|
|
|
$this->getRepository()->checkout('master'); |
64
|
|
|
$this->addFile('another file on master'); |
65
|
|
|
$this->getRepository()->commit('new commit on master', true); |
66
|
|
|
$lastCommitOnMaster = $this->getRepository()->getCommit(); |
67
|
|
|
$this->getRepository()->merge($this->getRepository()->getBranch('new-branch')); |
|
|
|
|
68
|
|
|
$log = $this->getRepository()->getLog(); |
69
|
|
|
$lastLogCommit = $log[0]; |
70
|
|
|
$this->assertContains($lastCommitOnMaster->getSha(), $lastLogCommit->getParents()); |
71
|
|
|
$this->assertContains($lastCommitOtherBranch->getSha(), $lastLogCommit->getParents()); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* testLogCountLimit |
76
|
|
|
*/ |
77
|
|
|
public function testLogCountLimit() |
78
|
|
|
{ |
79
|
|
|
$log = $this->getRepository()->getLog(null, null, null); |
80
|
|
|
$this->assertEquals(10, $log->count()); |
81
|
|
|
|
82
|
|
|
$log = $this->getRepository()->getLog(null, null, 10, null); |
83
|
|
|
$this->assertEquals(10, $log->count()); |
84
|
|
|
|
85
|
|
|
$log = $this->getRepository()->getLog(null, null, 50, null); |
86
|
|
|
$this->assertEquals(10, $log->count()); |
87
|
|
|
|
88
|
|
|
$log = $this->getRepository()->getLog(null, null, 60, null); |
89
|
|
|
$this->assertEquals(10, $log->count()); |
90
|
|
|
|
91
|
|
|
$log = $this->getRepository()->getLog(null, null, 1, null); |
92
|
|
|
$this->assertEquals(1, $log->count()); |
93
|
|
|
|
94
|
|
|
$log = $this->getRepository()->getLog(null, null, 0, null); |
95
|
|
|
$this->assertEquals(0, $log->count()); |
96
|
|
|
|
97
|
|
|
$log = $this->getRepository()->getLog(null, null, -1, null); |
98
|
|
|
$this->assertEquals(10, $log->count()); |
99
|
|
|
|
100
|
|
|
$log = $this->getRepository()->getLog(null, "test\ file\ 1", -1, null); |
101
|
|
|
$this->assertEquals(1, $log->count()); |
102
|
|
|
|
103
|
|
|
$log = $this->getRepository()->getLog(null, "test\ file*", -1, null); |
104
|
|
|
$this->assertEquals(10, $log->count()); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* testLogOffset |
109
|
|
|
*/ |
110
|
|
|
public function testLogOffset() |
111
|
|
|
{ |
112
|
|
|
$log = $this->getRepository()->getLog(null, null, null, 0); |
113
|
|
|
$this->assertEquals(10, $log->count()); |
114
|
|
|
|
115
|
|
|
$log = $this->getRepository()->getLog(null, null, null, 5); |
116
|
|
|
$this->assertEquals(5, $log->count()); |
117
|
|
|
|
118
|
|
|
$log = $this->getRepository()->getLog(null, null, null, 50); |
119
|
|
|
$this->assertEquals(0, $log->count()); |
120
|
|
|
|
121
|
|
|
$log = $this->getRepository()->getLog(null, null, null, 100); |
122
|
|
|
$this->assertEquals(0, $log->count()); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* testLogIndex |
127
|
|
|
*/ |
128
|
|
|
public function testLogIndex() |
129
|
|
|
{ |
130
|
|
|
$log = $this->getRepository()->getLog(null, null, null, null); |
131
|
|
|
|
132
|
|
|
// [0;50[ - 10 = 39 |
133
|
|
|
$this->assertEquals('test commit index:7', $log[2]->getMessage()->toString()); |
134
|
|
|
$this->assertEquals('test commit index:7', $log->index(2)->getMessage()->toString()); |
135
|
|
|
$this->assertEquals('test commit index:7', $log->offsetGet(2)->getMessage()->toString()); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* testLogToArray |
140
|
|
|
*/ |
141
|
|
|
public function testLogToArray() |
142
|
|
|
{ |
143
|
|
|
$log = $this->getRepository()->getLog(null, null, null, null); |
144
|
|
|
|
145
|
|
|
$this->assertTrue(is_array($log->toArray())); |
146
|
|
|
$this->assertInternalType('array', $log->toArray()); |
147
|
|
|
$this->assertEquals($log->count(), count($log->toArray())); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* testObjectLog |
152
|
|
|
*/ |
153
|
|
|
public function testObjectLog() |
154
|
|
|
{ |
155
|
|
|
$tree = $this->getRepository()->getTree(); |
156
|
|
|
$file = $tree[0]; |
|
|
|
|
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* testLogCreatedFromOutputLines |
161
|
|
|
*/ |
162
|
|
|
public function testLogCreatedFromOutputLines() |
163
|
|
|
{ |
164
|
|
|
$tree = $this->getRepository()->getTree(); |
165
|
|
|
$obj = $tree[count($tree) - 1]; |
166
|
|
|
$logCommand = new LogCommand(); |
167
|
|
|
$command = $logCommand->showObjectLog($obj); |
168
|
|
|
$log = Log::createFromOutputLines($this->getRepository(), $this->caller->execute($command)->getOutputLines()); |
169
|
|
|
$this->assertInstanceOf('GitElephant\Objects\Log', $log); |
170
|
|
|
$this->assertCount(1, $log); |
171
|
|
|
|
172
|
|
|
} |
173
|
|
|
} |
174
|
|
|
|
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: