1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
14
|
|
|
* |
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
16
|
|
|
* and is licensed under the LGPL. For more information please see |
17
|
|
|
* <http://phing.info>. |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
namespace Phing\Test\Task\Optional\Git; |
21
|
|
|
|
22
|
|
|
use Phing\Test\Support\BuildFileTest; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @author Victor Farazdagi <[email protected]> |
26
|
|
|
* @requires OS ^(?:(?!Win).)*$ |
27
|
|
|
*/ |
28
|
|
|
class GitLogTaskTest extends BuildFileTest |
29
|
|
|
{ |
30
|
|
|
private $testCommits = [ |
31
|
|
|
[ |
32
|
|
|
'commit' => '6dbaf4508e75dcd426b5b974a67c462c70d46e1f', |
33
|
|
|
'author' => 'Victor Farazdagi <[email protected]>', |
34
|
|
|
'date' => 'Sun Sep 26 21:14:44 2010 +0400', |
35
|
|
|
'msg' => 'Inited', |
36
|
|
|
'msg-full' => '', |
37
|
|
|
'From' => '6dbaf4508e75dcd426b5b974a67c462c70d46e1f Mon Sep 17 00:00:00 2001', |
38
|
|
|
'From:' => 'Victor Farazdagi <[email protected]>', |
39
|
|
|
'Date' => 'Sun, 26 Sep 2010 21:14:44 +0400', |
40
|
|
|
'Subject' => '[PATCH] Inited', |
41
|
|
|
], |
42
|
|
|
[ |
43
|
|
|
'commit' => 'b8cddb3fa5f408560d0d00d6c8721fe333895888', |
44
|
|
|
'author' => 'Victor Farazdagi <[email protected]>', |
45
|
|
|
'date' => 'Sun Jan 23 22:53:07 2011 +0300', |
46
|
|
|
'msg' => 'Added file1 + file2', |
47
|
|
|
'msg-full' => '', |
48
|
|
|
'From' => 'b8cddb3fa5f408560d0d00d6c8721fe333895888 Mon Sep 17 00:00:00 2001', |
49
|
|
|
'From:' => 'Victor Farazdagi <[email protected]>', |
50
|
|
|
'Date' => 'Sun, 23 Jan 2011 22:53:07 +0300', |
51
|
|
|
'Subject' => '[PATCH] Added file1 + file2', |
52
|
|
|
], |
53
|
|
|
[ |
54
|
|
|
'commit' => 'c573116f395d36497a1ac1dba565ecd3d3944277', |
55
|
|
|
'author' => 'Victor Farazdagi <[email protected]>', |
56
|
|
|
'date' => 'Sun Jan 23 22:53:19 2011 +0300', |
57
|
|
|
'msg' => 'Added file3', |
58
|
|
|
'msg-full' => '', |
59
|
|
|
'From' => 'c573116f395d36497a1ac1dba565ecd3d3944277 Mon Sep 17 00:00:00 2001', |
60
|
|
|
'From:' => 'Victor Farazdagi <[email protected]>', |
61
|
|
|
'Date' => 'Sun, 23 Jan 2011 22:53:19 +0300', |
62
|
|
|
'Subject' => '[PATCH] Added file3', |
63
|
|
|
], |
64
|
|
|
[ |
65
|
|
|
'commit' => '2b4a5409bf60813b6a84d583bbdcbed25c7c3a00', |
66
|
|
|
'author' => 'Victor Farazdagi <[email protected]>', |
67
|
|
|
'date' => 'Sun Jan 23 22:53:42 2011 +0300', |
68
|
|
|
'msg' => 'Removed file3', |
69
|
|
|
'msg-full' => '', |
70
|
|
|
'From' => '2b4a5409bf60813b6a84d583bbdcbed25c7c3a00 Mon Sep 17 00:00:00 2001', |
71
|
|
|
'From:' => 'Victor Farazdagi <[email protected]>', |
72
|
|
|
'Date' => 'Sun, 23 Jan 2011 22:53:42 +0300', |
73
|
|
|
'Subject' => '[PATCH] Removed file3', |
74
|
|
|
], |
75
|
|
|
[ |
76
|
|
|
'commit' => 'ee07085160003ffd1100867deb6059bae0c45455', |
77
|
|
|
'author' => 'Victor Farazdagi <[email protected]>', |
78
|
|
|
'date' => 'Sun Jan 23 23:38:34 2011 +0300', |
79
|
|
|
'msg' => 'Title: file4 was added', |
80
|
|
|
'msg-full' => 'Full commit message: and here goes some elaboration on what has been done.', |
81
|
|
|
'From' => 'ee07085160003ffd1100867deb6059bae0c45455 Mon Sep 17 00:00:00 2001', |
82
|
|
|
'From:' => 'Victor Farazdagi <[email protected]>', |
83
|
|
|
'Date' => 'Sun, 23 Jan 2011 23:38:34 +0300', |
84
|
|
|
'Subject' => '[PATCH] Title: file4 was added', |
85
|
|
|
], |
86
|
|
|
[ |
87
|
|
|
'commit' => '1b767b75bb5329f4e53345c516c0a9f4ed32d330', |
88
|
|
|
'author' => 'Victor Farazdagi <[email protected]>', |
89
|
|
|
'date' => 'Mon Jan 24 09:58:33 2011 +0300', |
90
|
|
|
'msg' => 'Added file5', |
91
|
|
|
'msg-full' => 'This file was added one day after file1, file2, file3 and file4 were added', |
92
|
|
|
'From' => '1b767b75bb5329f4e53345c516c0a9f4ed32d330 Mon Sep 17 00:00:00 2001', |
93
|
|
|
'From:' => 'Victor Farazdagi <[email protected]>', |
94
|
|
|
'Date' => 'Mon, 24 Jan 2011 09:58:33 +0300', |
95
|
|
|
'Subject' => '[PATCH] Added file5', |
96
|
|
|
], |
97
|
|
|
|
98
|
|
|
]; |
99
|
|
|
|
100
|
|
|
public function setUp(): void |
101
|
|
|
{ |
102
|
|
|
if (is_readable(PHING_TEST_BASE . '/tmp/git')) { |
103
|
|
|
// make sure we purge previously created directory |
104
|
|
|
// if left-overs from previous run are found |
105
|
|
|
$this->rmdir(PHING_TEST_BASE . '/tmp/git'); |
106
|
|
|
} |
107
|
|
|
// set temp directory used by test cases |
108
|
|
|
mkdir(PHING_TEST_BASE . '/tmp/git'); |
109
|
|
|
|
110
|
|
|
$this->configureProject( |
111
|
|
|
PHING_TEST_BASE |
112
|
|
|
. '/etc/tasks/ext/git/GitLogTaskTest.xml' |
113
|
|
|
); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
public function tearDown(): void |
117
|
|
|
{ |
118
|
|
|
$this->rmdir(PHING_TEST_BASE . '/tmp/git'); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
public function testGitLogWithoutParams() |
122
|
|
|
{ |
123
|
|
|
$this->executeTarget('gitLogWithoutParams'); |
124
|
|
|
foreach ($this->testCommits as $commit) { |
125
|
|
|
$this->assertInLogs($commit['date']); |
126
|
|
|
$this->assertInLogs($commit['author']); |
127
|
|
|
$this->assertInLogs($commit['commit']); |
128
|
|
|
$this->assertInLogs($commit['msg']); |
129
|
|
|
if (strlen($commit['msg-full'])) { |
130
|
|
|
$this->assertInLogs($commit['msg-full']); |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
public function testGitWithMostParams() |
136
|
|
|
{ |
137
|
|
|
$this->executeTarget('gitLogWithMostParams'); |
138
|
|
|
$lastTwoCommits = array_slice($this->testCommits, -2); |
139
|
|
|
$allOtherCommits = array_slice($this->testCommits, 0, -2); |
140
|
|
|
|
141
|
|
|
// test max-count |
142
|
|
|
foreach ($lastTwoCommits as $commit) { |
143
|
|
|
$this->assertInLogs($commit['commit']); |
144
|
|
|
$this->assertInLogs($commit['msg']); |
145
|
|
|
} |
146
|
|
|
foreach ($allOtherCommits as $commit) { |
147
|
|
|
$this->assertNotInLogs($commit['commit']); |
148
|
|
|
$this->assertNotInLogs($commit['msg']); |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
public function testGitOutputPropertySet() |
153
|
|
|
{ |
154
|
|
|
$this->executeTarget('gitLogOutputPropertySet'); |
155
|
|
|
$this->assertPropertyEquals('gitLogOutput', '1b767b75bb5329f4e53345c516c0a9f4ed32d330 Added file5'); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
public function testGitLogNameStatus() |
159
|
|
|
{ |
160
|
|
|
$this->executeTarget('gitLogNameStatusSet'); |
161
|
|
|
$this->assertInLogs("A\tfile1"); |
162
|
|
|
$this->assertInLogs("A\tfile2"); |
163
|
|
|
$this->assertInLogs("A\tfile3"); |
164
|
|
|
$this->assertInLogs("A\tREADME"); |
165
|
|
|
$this->assertInLogs("D\tfile3"); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* @todo Need to implement the Git relative date calculation |
170
|
|
|
*/ |
171
|
|
|
public function testGitDateRelative() |
172
|
|
|
{ |
173
|
|
|
$this->markTestSkipped('Need to implement the Git relative date calculation'); |
174
|
|
|
$this->executeTarget('gitLogDateRelative'); |
175
|
|
|
foreach ($this->testCommits as $commit) { |
176
|
|
|
$timestamp = strtotime($commit['date']); |
177
|
|
|
$this->assertInLogs($this->getRelativeDate($timestamp)); |
178
|
|
|
} |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
public function testGitSinceUntilSet() |
182
|
|
|
{ |
183
|
|
|
$this->executeTarget('gitLogSinceUntilSet'); |
184
|
|
|
$this->assertNotInLogs('6dbaf4508e75dcd426b5b974a67c462c70d46e1f Inited'); |
185
|
|
|
$this->assertNotInLogs('1b767b75bb5329f4e53345c516c0a9f4ed32d330 Added file5'); |
186
|
|
|
$this->assertInLogs('ee07085160003ffd1100867deb6059bae0c45455 Title: file4 was added'); |
187
|
|
|
$this->assertInLogs('2b4a5409bf60813b6a84d583bbdcbed25c7c3a00 Removed file3'); |
188
|
|
|
$this->assertInLogs('c573116f395d36497a1ac1dba565ecd3d3944277 Added file3'); |
189
|
|
|
$this->assertInLogs('b8cddb3fa5f408560d0d00d6c8721fe333895888 Added file1 + file2'); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
public function testGitBeforeAfterSet() |
193
|
|
|
{ |
194
|
|
|
$this->executeTarget('gitLogBeforeAfterSet'); |
195
|
|
|
$this->assertNotInLogs('6dbaf4508e75dcd426b5b974a67c462c70d46e1f Inited'); |
196
|
|
|
$this->assertNotInLogs('1b767b75bb5329f4e53345c516c0a9f4ed32d330 Added file5'); |
197
|
|
|
$this->assertInLogs('ee07085160003ffd1100867deb6059bae0c45455 Title: file4 was added'); |
198
|
|
|
$this->assertInLogs('2b4a5409bf60813b6a84d583bbdcbed25c7c3a00 Removed file3'); |
199
|
|
|
$this->assertInLogs('c573116f395d36497a1ac1dba565ecd3d3944277 Added file3'); |
200
|
|
|
$this->assertInLogs('b8cddb3fa5f408560d0d00d6c8721fe333895888 Added file1 + file2'); |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
public function testGitFormatOneLine() |
204
|
|
|
{ |
205
|
|
|
$this->executeTarget('gitLogFormatOneLine'); |
206
|
|
|
foreach ($this->testCommits as $commit) { |
207
|
|
|
$this->assertNotInLogs($commit['author']); |
208
|
|
|
$this->assertNotInLogs($commit['date']); |
209
|
|
|
$this->assertInLogs($commit['commit']); |
210
|
|
|
$this->assertInLogs($commit['msg']); |
211
|
|
|
} |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
public function testGitFormatShort() |
215
|
|
|
{ |
216
|
|
|
$this->executeTarget('gitLogFormatShort'); |
217
|
|
|
foreach ($this->testCommits as $commit) { |
218
|
|
|
$this->assertNotInLogs($commit['date']); |
219
|
|
|
$this->assertInLogs($commit['author']); |
220
|
|
|
$this->assertInLogs($commit['commit']); |
221
|
|
|
$this->assertInLogs($commit['msg']); |
222
|
|
|
} |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
public function testGitFormatMedium() |
226
|
|
|
{ |
227
|
|
|
$this->executeTarget('gitLogFormatMedium'); |
228
|
|
|
foreach ($this->testCommits as $commit) { |
229
|
|
|
$this->assertInLogs($commit['date']); |
230
|
|
|
$this->assertInLogs($commit['author']); |
231
|
|
|
$this->assertInLogs($commit['commit']); |
232
|
|
|
$this->assertInLogs($commit['msg']); |
233
|
|
|
if (strlen($commit['msg-full'])) { |
234
|
|
|
$this->assertInLogs($commit['msg-full']); |
235
|
|
|
} |
236
|
|
|
} |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
public function testGitFormatFull() |
240
|
|
|
{ |
241
|
|
|
$this->executeTarget('gitLogFormatFull'); |
242
|
|
|
foreach ($this->testCommits as $commit) { |
243
|
|
|
$this->assertNotInLogs($commit['date']); |
244
|
|
|
$this->assertInLogs('Author: ' . $commit['author']); |
245
|
|
|
$this->assertInLogs('Commit: ' . $commit['author']); |
246
|
|
|
$this->assertInLogs('commit ' . $commit['commit']); |
247
|
|
|
$this->assertInLogs($commit['msg']); |
248
|
|
|
if (strlen($commit['msg-full'])) { |
249
|
|
|
$this->assertInLogs($commit['msg-full']); |
250
|
|
|
} |
251
|
|
|
} |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
public function testGitFormatFuller() |
255
|
|
|
{ |
256
|
|
|
$this->executeTarget('gitLogFormatFuller'); |
257
|
|
|
foreach ($this->testCommits as $commit) { |
258
|
|
|
$this->assertInLogs('Author: ' . $commit['author']); |
259
|
|
|
$this->assertInLogs('AuthorDate: ' . $commit['date']); |
260
|
|
|
$this->assertInLogs('Commit: ' . $commit['author']); |
261
|
|
|
$this->assertInLogs('CommitDate: ' . $commit['date']); |
262
|
|
|
$this->assertInLogs('commit ' . $commit['commit']); |
263
|
|
|
$this->assertInLogs($commit['msg']); |
264
|
|
|
if (strlen($commit['msg-full'])) { |
265
|
|
|
$this->assertInLogs($commit['msg-full']); |
266
|
|
|
} |
267
|
|
|
} |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
public function testGitFormatEmail() |
271
|
|
|
{ |
272
|
|
|
$this->executeTarget('gitLogFormatEmail'); |
273
|
|
|
foreach ($this->testCommits as $commit) { |
274
|
|
|
$this->assertInLogs('From ' . $commit['From']); |
275
|
|
|
$this->assertInLogs('From: ' . $commit['From:']); |
276
|
|
|
$this->assertInLogs('Date: ' . $commit['Date']); |
277
|
|
|
$this->assertInLogs('Subject: ' . $commit['Subject']); |
278
|
|
|
if (strlen($commit['msg-full'])) { |
279
|
|
|
$this->assertInLogs($commit['msg-full']); |
280
|
|
|
} |
281
|
|
|
} |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
public function testGitFormatCustom() |
285
|
|
|
{ |
286
|
|
|
$this->executeTarget('gitLogFormatCustom'); |
287
|
|
|
foreach ($this->testCommits as $commit) { |
288
|
|
|
$this->assertInLogs( |
289
|
|
|
sprintf('The author of %s was %s', $commit['commit'], $commit['author']) |
290
|
|
|
); |
291
|
|
|
} |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
public function testNoRepositorySpecified() |
295
|
|
|
{ |
296
|
|
|
$this->expectBuildExceptionContaining( |
297
|
|
|
'noRepository', |
298
|
|
|
'Repo dir is required', |
299
|
|
|
'"repository" is required parameter' |
300
|
|
|
); |
301
|
|
|
} |
302
|
|
|
} |
303
|
|
|
|