|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* User: matteo |
|
5
|
|
|
* Date: 28/05/13 |
|
6
|
|
|
* Time: 21.42 |
|
7
|
|
|
* Just for fun... |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace GitElephant\Status; |
|
11
|
|
|
|
|
12
|
|
|
use GitElephant\TestCase; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Class StatusTest |
|
16
|
|
|
* |
|
17
|
|
|
* @package GitElephant\Status |
|
18
|
|
|
*/ |
|
19
|
|
|
class StatusTest extends TestCase |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* setUp |
|
23
|
|
|
*/ |
|
24
|
|
|
public function setUp(): void |
|
25
|
|
|
{ |
|
26
|
|
|
$this->getRepository()->init(); |
|
27
|
|
|
$this->addFile('initial'); |
|
28
|
|
|
$this->getRepository()->commit('initial commit', true); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* testStatusIndexWithoutUntracked |
|
33
|
|
|
*/ |
|
34
|
|
|
public function testStatusIndexWithoutUntracked(): void |
|
35
|
|
|
{ |
|
36
|
|
|
$this->addFile('test'); |
|
37
|
|
|
$s = $this->repository->getIndexStatus(); |
|
38
|
|
|
$this->assertCount(0, $s->all()); |
|
39
|
|
|
$this->assertCount(0, $s->untracked()); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* status test |
|
44
|
|
|
*/ |
|
45
|
|
|
public function testUntracked(): void |
|
46
|
|
|
{ |
|
47
|
|
|
$this->addFile('test'); |
|
48
|
|
|
$s = $this->repository->getStatus(); |
|
49
|
|
|
$this->assertCount(1, $s->untracked()); |
|
50
|
|
|
$this->assertInstanceOf('\Traversable', $s->untracked()); |
|
51
|
|
|
$this->assertEquals('untracked', $s->untracked()->first()->get()->getDescription()); |
|
52
|
|
|
$this->assertFalse($s->untracked()->first()->get()->isRenamed()); |
|
53
|
|
|
$this->assertInterfaces($s->untracked()); |
|
54
|
|
|
foreach ($s->untracked() as $file) { |
|
55
|
|
|
$this->assertInstanceOf('GitElephant\Status\StatusFile', $file); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* modified |
|
61
|
|
|
*/ |
|
62
|
|
|
public function testModified(): void |
|
63
|
|
|
{ |
|
64
|
|
|
$this->addFile('test', null, 'test'); |
|
65
|
|
|
$this->repository->stage(); |
|
66
|
|
|
$this->updateFile('test', 'test content'); |
|
67
|
|
|
$s = $this->repository->getStatus(); |
|
68
|
|
|
$this->assertCount(1, $s->modified()); |
|
69
|
|
|
$this->assertFalse($s->modified()->first()->get()->isRenamed()); |
|
70
|
|
|
$this->assertInterfaces($s->modified()); |
|
71
|
|
|
foreach ($s->modified() as $file) { |
|
72
|
|
|
$this->assertInstanceOf('GitElephant\Status\StatusFile', $file); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* added |
|
78
|
|
|
*/ |
|
79
|
|
|
public function testAdded(): void |
|
80
|
|
|
{ |
|
81
|
|
|
$this->addFile('test'); |
|
82
|
|
|
$this->repository->stage(); |
|
83
|
|
|
$s = $this->repository->getStatus(); |
|
84
|
|
|
$this->assertCount(1, $s->added()); |
|
85
|
|
|
$this->assertFalse($s->added()->first()->get()->isRenamed()); |
|
86
|
|
|
$this->assertInterfaces($s->added()); |
|
87
|
|
|
foreach ($s->added() as $file) { |
|
88
|
|
|
$this->assertInstanceOf('GitElephant\Status\StatusFile', $file); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* deleted |
|
94
|
|
|
*/ |
|
95
|
|
|
public function testDeleted(): void |
|
96
|
|
|
{ |
|
97
|
|
|
$this->addFile('test'); |
|
98
|
|
|
$this->repository->commit('test message', true); |
|
99
|
|
|
$this->removeFile('test'); |
|
100
|
|
|
$s = $this->repository->getStatus(); |
|
101
|
|
|
$this->assertCount(1, $s->deleted()); |
|
102
|
|
|
$this->assertFalse($s->deleted()->first()->get()->isRenamed()); |
|
103
|
|
|
$this->assertInterfaces($s->deleted()); |
|
104
|
|
|
foreach ($s->deleted() as $file) { |
|
105
|
|
|
$this->assertInstanceOf('GitElephant\Status\StatusFile', $file); |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* renamed |
|
111
|
|
|
*/ |
|
112
|
|
|
public function testRenamed(): void |
|
113
|
|
|
{ |
|
114
|
|
|
$this->addFile('test', null, 'test content'); |
|
115
|
|
|
$this->repository->commit('test message', true); |
|
116
|
|
|
$this->renameFile('test', 'test2'); |
|
117
|
|
|
$s = $this->repository->getStatus(); |
|
118
|
|
|
$this->assertCount(1, $s->renamed()); |
|
119
|
|
|
$this->assertTrue($s->renamed()->first()->get()->isRenamed()); |
|
120
|
|
|
$this->assertInterfaces($s->renamed()); |
|
121
|
|
|
foreach ($s->renamed() as $file) { |
|
122
|
|
|
$this->assertInstanceOf('GitElephant\Status\StatusFile', $file); |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* testWorkingTreeStatus |
|
128
|
|
|
*/ |
|
129
|
|
|
public function testWorkingTreeStatus(): void |
|
130
|
|
|
{ |
|
131
|
|
|
/*$this->markTestSkipped( |
|
132
|
|
|
'Caller::execute throws a RuntimeException here because. Repository::unstage |
|
133
|
|
|
invokes "git reset HEAD -- test", which returns 1 (not 0) on git < 1.8, even though it executes successfully. |
|
134
|
|
|
On new git version this is not happening anymore.' |
|
135
|
|
|
);*/ |
|
136
|
|
|
|
|
137
|
|
|
$this->addFile('test', null, 'test content'); |
|
138
|
|
|
$wt = $this->repository->getWorkingTreeStatus(); |
|
139
|
|
|
$this->assertCount(1, $wt->untracked()); |
|
140
|
|
|
|
|
141
|
|
|
$this->repository->stage('test'); |
|
142
|
|
|
$wt = $this->repository->getWorkingTreeStatus(); |
|
143
|
|
|
$index = $this->repository->getIndexStatus(); |
|
144
|
|
|
$this->assertCount(0, $wt->untracked()); |
|
145
|
|
|
$this->assertCount(1, $index->added()); |
|
146
|
|
|
|
|
147
|
|
|
$this->repository->unstage('test'); |
|
148
|
|
|
$wt = $this->repository->getWorkingTreeStatus(); |
|
149
|
|
|
$index = $this->repository->getIndexStatus(); |
|
150
|
|
|
$this->assertCount(1, $wt->untracked()); |
|
151
|
|
|
$this->assertCount(0, $index->added()); |
|
152
|
|
|
|
|
153
|
|
|
$this->repository->commit('test-commit', true); |
|
154
|
|
|
$wt = $this->repository->getWorkingTreeStatus(); |
|
155
|
|
|
$index = $this->repository->getIndexStatus(); |
|
156
|
|
|
$this->assertCount(0, $wt->all()); |
|
157
|
|
|
$this->assertCount(0, $index->all()); |
|
158
|
|
|
|
|
159
|
|
|
$this->addFile('test', null, 'new content'); |
|
160
|
|
|
$wt = $this->repository->getWorkingTreeStatus(); |
|
161
|
|
|
$index = $this->repository->getIndexStatus(); |
|
162
|
|
|
$this->assertCount(1, $wt->modified()); |
|
163
|
|
|
$this->assertCount(0, $index->modified()); |
|
164
|
|
|
|
|
165
|
|
|
$this->repository->stage('test'); |
|
166
|
|
|
$wt = $this->repository->getWorkingTreeStatus(); |
|
167
|
|
|
$index = $this->repository->getIndexStatus(); |
|
168
|
|
|
$this->assertCount(0, $wt->modified()); |
|
169
|
|
|
$this->assertCount(1, $index->modified()); |
|
170
|
|
|
|
|
171
|
|
|
$this->removeFile('test'); |
|
172
|
|
|
$wt = $this->repository->getWorkingTreeStatus(); |
|
173
|
|
|
$index = $this->repository->getIndexStatus(); |
|
174
|
|
|
$this->assertCount(1, $wt->deleted()); |
|
175
|
|
|
$this->assertCount(1, $index->modified()); |
|
176
|
|
|
|
|
177
|
|
|
// Caller::execute throws a RuntimeException here because |
|
178
|
|
|
// Repository::unstage invokes 'git reset HEAD -- test', |
|
179
|
|
|
// which returns 1 (not 0), even though it executes successfully |
|
180
|
|
|
// |
|
181
|
|
|
// @see http://stackoverflow.com/questions/9154674/why-git-reset-file-returns-1 |
|
182
|
|
|
$this->repository->unstage('test'); |
|
183
|
|
|
$wt = $this->repository->getWorkingTreeStatus(); |
|
184
|
|
|
$index = $this->repository->getIndexStatus(); |
|
185
|
|
|
$this->assertCount(1, $wt->deleted()); |
|
186
|
|
|
$this->assertCount(0, $index->all()); |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
/** |
|
190
|
|
|
* Test the name, type and describe getter & setter |
|
191
|
|
|
* |
|
192
|
|
|
* @return void |
|
193
|
|
|
*/ |
|
194
|
|
|
public function testStatusFiles(): void |
|
195
|
|
|
{ |
|
196
|
|
|
$this->addFile('test'); |
|
197
|
|
|
$this->repository->stage(); |
|
198
|
|
|
$s = $this->repository->getStatus(); |
|
199
|
|
|
$files = $s->all(); |
|
200
|
|
|
$this->assertCount(1, $files); |
|
201
|
|
|
foreach ($files as $file) { |
|
202
|
|
|
$this->assertEquals('test', $file->getName()); |
|
203
|
|
|
$this->assertEquals(null, $file->getType()); |
|
204
|
|
|
$file->setDescription('test'); |
|
205
|
|
|
$this->assertEquals('test', $file->getDescription()); |
|
206
|
|
|
$file->setType(StatusFile::UNMODIFIED); |
|
207
|
|
|
$this->assertEquals(StatusFile::UNMODIFIED, $file->getType()); |
|
208
|
|
|
} |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
/** |
|
212
|
|
|
* @param mixed $subject |
|
213
|
|
|
*/ |
|
214
|
|
|
private function assertInterfaces($subject): void |
|
215
|
|
|
{ |
|
216
|
|
|
$this->assertInstanceOf('\Countable', $subject); |
|
217
|
|
|
$this->assertInstanceOf('\Traversable', $subject); |
|
218
|
|
|
$this->assertInstanceOf('\IteratorAggregate', $subject); |
|
219
|
|
|
} |
|
220
|
|
|
} |
|
221
|
|
|
|