Passed
Push — main ( 2c83d5...fb3f8a )
by Siad
05:21
created

GitMergeTaskTest::testFastForwardCommitSet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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 GitMergeTaskTest extends BuildFileTest
29
{
30
    public function setUp(): void
31
    {
32
        if (is_readable(PHING_TEST_BASE . '/tmp/git')) {
33
            // make sure we purge previously created directory
34
            // if left-overs from previous run are found
35
            $this->rmdir(PHING_TEST_BASE . '/tmp/git');
36
        }
37
        // set temp directory used by test cases
38
        mkdir(PHING_TEST_BASE . '/tmp/git');
39
40
        $this->configureProject(
41
            PHING_TEST_BASE
42
            . '/etc/tasks/ext/git/GitMergeTaskTest.xml'
43
        );
44
    }
45
46
    public function tearDown(): void
47
    {
48
        $this->rmdir(PHING_TEST_BASE . '/tmp/git');
49
    }
50
51
    public function testAllParamsSet()
52
    {
53
        $repository = PHING_TEST_BASE . '/tmp/git';
0 ignored issues
show
Unused Code introduced by
The assignment to $repository is dead and can be removed.
Loading history...
54
        $this->executeTarget('allParamsSet');
55
        $this->assertInLogs('git-merge: replaying "merge-test-1 merge-test-2" commits');
56
        $this->assertInLogs('git-merge output: Already up');
57
    }
58
59
    public function testNoCommitSet()
60
    {
61
        $repository = PHING_TEST_BASE . '/tmp/git';
0 ignored issues
show
Unused Code introduced by
The assignment to $repository is dead and can be removed.
Loading history...
62
        $this->executeTarget('noCommitSet');
63
        $this->assertInLogs('git-merge: replaying "6dbaf4508e75dcd426b5b974a67c462c70d46e1f" commits');
64
        $this->assertInLogs('git-merge output: Already up');
65
    }
66
67
    public function testRemoteSet()
68
    {
69
        $repository = PHING_TEST_BASE . '/tmp/git';
0 ignored issues
show
Unused Code introduced by
The assignment to $repository is dead and can be removed.
Loading history...
70
        $this->executeTarget('remoteSet');
71
        $this->assertInLogs('git-merge: replaying "6dbaf4508e75dcd426b5b974a67c462c70d46e1f" commits');
72
        $this->assertInLogs('git-merge output: Already up');
73
    }
74
75
    public function testFastForwardCommitSet()
76
    {
77
        $repository = PHING_TEST_BASE . '/tmp/git';
0 ignored issues
show
Unused Code introduced by
The assignment to $repository is dead and can be removed.
Loading history...
78
        $this->executeTarget('fastForwardCommitSet');
79
        $this->assertInLogs('git-merge command: LC_ALL=C && git merge --no-ff \'origin/master\'');
80
        $this->assertInLogs('git-merge: replaying "origin/master" commits');
81
        $this->assertInLogs('Merge remote-tracking branch \'origin/master\' into merge-test-1');
82
    }
83
84
    public function testNoRepositorySpecified()
85
    {
86
        $this->expectBuildExceptionContaining(
87
            'noRepository',
88
            'Repo dir is required',
89
            '"repository" is required parameter'
90
        );
91
    }
92
93
    public function testNoRemotesSpecified()
94
    {
95
        $this->expectBuildExceptionContaining(
96
            'noRemotes',
97
            'At least one commit is required',
98
            '"remote" is required parameter'
99
        );
100
    }
101
102
    public function testWrongStrategySet()
103
    {
104
        $this->expectBuildExceptionContaining(
105
            'wrongStrategySet',
106
            'Wrong strategy passed',
107
            'Could not find merge strategy \'plain-wrong\''
108
        );
109
    }
110
}
111