aboutsummaryrefslogtreecommitdiffstats
path: root/library/kzykhys/git/test/PHPGit/Command/BranchCommandTest.php
blob: 4deeea3670498eedcd52130d153a7c8580ba0a07 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php

use PHPGit\Git;
use Symfony\Component\Filesystem\Filesystem;

require_once __DIR__ . '/../BaseTestCase.php';

class BranchCommandTest extends BaseTestCase
{

    public function setUp()
    {
        parent::setUp();

        $filesystem = new Filesystem();

        $git = new Git();
        $git->init($this->directory);
        $git->setRepository($this->directory);

        $filesystem->dumpFile($this->directory . '/test.txt', '');
        $git->add('test.txt');
        $git->commit('Initial commit');
    }

    public function testBranch()
    {
        $git = new Git();
        $git->setRepository($this->directory);

        $branches = $git->branch();

        $this->assertCount(1, $branches);
        $this->assertEquals('master', $branches['master']['name']);
        $this->assertTrue($branches['master']['current']);
        $this->assertEquals('Initial commit', $branches['master']['title']);
    }

    public function testAllBranch()
    {
        $git = new Git();
        $git->clone('file://' . realpath($this->directory), $this->directory.'2');
        $git->setRepository($this->directory.'2');

        $branches = $git->branch(array('remotes' => true));
        $this->assertArrayHasKey('origin/master', $branches);

        $branches = $git->branch(array('all' => true));
        $this->assertArrayHasKey('master', $branches);
        $this->assertArrayHasKey('remotes/origin/master', $branches);

        $filesystem = new Filesystem();
        $filesystem->remove($this->directory.'2');
    }

    public function testBranchCreate()
    {
        $git = new Git();
        $git->setRepository($this->directory);

        $git->branch->create('1.0');
        $branches = $git->branch();
        $this->assertCount(2, $branches);

        $git->branch->create('1.0-fix', '1.0', array('force' => true));
        $branches = $git->branch();
        $this->assertCount(3, $branches);
        $this->assertArrayHasKey('1.0', $branches);
        $this->assertArrayHasKey('1.0-fix', $branches);
    }

    public function testBranchMove()
    {
        $git = new Git();
        $git->setRepository($this->directory);
        $git->branch->create('1.0');
        $git->branch->move('1.0', '1.0.x');
        $branches = $git->branch();
        $this->assertCount(2, $branches);
        $this->assertArrayHasKey('1.0.x', $branches);

        $git->branch->move('1.0.x', '2.x', array('force' => true));
        $branches = $git->branch();
        $this->assertCount(2, $branches);
        $this->assertArrayHasKey('2.x', $branches);
    }

    public function testBranchDelete()
    {
        $git = new Git();
        $git->setRepository($this->directory);
        $git->branch->create('1.0');
        $git->branch->create('2.0');
        $branches = $git->branch();
        $this->assertCount(3, $branches);

        $git->branch->delete('1.0');
        $branches = $git->branch();
        $this->assertCount(2, $branches);

        $git->branch->delete('2.0', array('force' => true));
        $branches = $git->branch();
        $this->assertCount(1, $branches);
    }

}