RemoteCommandTest::testShow()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * This file is part of the GitElephant package.
5
 *
6
 * (c) Matteo Giachino <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * Just for fun...
12
 */
13
14
namespace GitElephant\Command;
15
16
use GitElephant\TestCase;
17
18
/**
19
 * Class RemoteCommandTest
20
 *
21
 * @package GitElephant\Command
22
 * @author  David Neimeyer <[email protected]>
23
 */
24
class RemoteCommandTest extends TestCase
25
{
26
    protected $startBranchName = 'test_branch';
27
    protected $startTagName = 'test_start_tag';
28
29
    /**
30
     * setUp
31
     */
32
    public function setUp(): void
33
    {
34
        $this->initRepository();
35
        $repo = $this->getRepository();
36
        $repo->init();
37
        $this->addFile('test');
38
        $repo->commit('test', true);
39
        $repo->createTag($this->startTagName);
40
        $repo->createBranch($this->startBranchName);
41
        $repo->checkout($this->startBranchName);
42
    }
43
44
    /**
45
     * Validate generated command when no arguements and no repository are used
46
     */
47
    public function testRemoteNoArgs(): void
48
    {
49
        $actual = RemoteCommand::getInstance()->remote();
50
        $expected = "remote";
51
        $this->assertEquals($expected, $actual, 'remote() without arguments is just the remote command');
52
    }
53
54
    /**
55
     * validate git-remote show [name]
56
     */
57
    public function testShow(): void
58
    {
59
        $remotename = 'foobar';
60
        $actual = RemoteCommand::getInstance()->show($remotename);
61
        $expected = "remote show '$remotename'";
62
        $this->assertEquals($expected, $actual, 'show() builds remote command with show subcommand');
63
64
        $actual = RemoteCommand::getInstance()->show($remotename, false);
65
        $expected = "remote show '-n' '$remotename'";
66
        $this->assertEquals($expected, $actual, 'show(, true) builds remote command with show subcommand and -n flag');
67
    }
68
69
    /**
70
     * validate git-remote --verbose
71
     */
72
    public function testVerbose(): void
73
    {
74
        $actual = RemoteCommand::getInstance()->verbose();
75
        $expected = "remote '--verbose'";
76
        $this->assertEquals($expected, $actual, 'show() builds remote command with show subcommand');
77
    }
78
79
    /**
80
     * validate git-remote add [options] <name> <url>
81
     */
82
    public function testAdd(): void
83
    {
84
        $name = 'foobar';
85
        $url = '[email protected]:/Foo/Bar.git';
86
        $options = [
87
            '-t bazblurg',
88
            '--mirror=fetch',
89
            '--tags'
90
        ];
91
        $actual = RemoteCommand::getInstance()->add($name, $url, $options);
92
        $expected = "remote add '-t' 'bazblurg' '--mirror=fetch' '--tags' '$name' '$url'";
93
        $this->assertEquals($expected, $actual, 'add() builds remote command with add subcommand');
94
    }
95
}
96