Test Failed
Push — master ( 440ce5...0cdbc1 )
by Siad
07:01
created

GitLogTaskTest::testGitBeforeAfterSet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

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