SubCommandCommandTest::testGetCommand()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 44

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 44
rs 9.216
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 SubCommandCommandTest extends TestCase
25
{
26
    /**
27
     * verify SubCommandCommands behavior, which is slightly
28
     * different that BaseCommand, for more sophisticated needs
29
     */
30
    public function testGetCommand(): void
31
    {
32
        $cmdName = 'foo';
33
        $subOne = 'bar';
34
        $subTwo = 'baz';
35
        $subThree = 'blurg';
36
        $argOne = '--opt1';
37
        $argTwo = '--opt2';
38
        $argTwoValue = 'val2';
39
        $expected = "foo '$argOne' '$argTwo' '$argTwoValue' '$subOne' '$subTwo' '$subThree'";
40
41
        $subcmd = new SubCommandCommand();
42
43
        $rmeth = new \ReflectionMethod($subcmd, 'addCommandName');
44
        $rmeth->setAccessible(true);
45
        $rmeth->invoke($subcmd, $cmdName);
46
47
        $rmeth = new \ReflectionMethod($subcmd, 'addCommandSubject');
48
        $rmeth->setAccessible(true);
49
        $rmeth->invoke($subcmd, $subOne);
50
51
        $rmeth = new \ReflectionMethod($subcmd, 'addCommandSubject');
52
        $rmeth->setAccessible(true);
53
        $rmeth->invoke($subcmd, $subTwo);
54
55
        $rmeth = new \ReflectionMethod($subcmd, 'addCommandSubject');
56
        $rmeth->setAccessible(true);
57
        $rmeth->invoke($subcmd, $subThree);
58
59
        $rmeth = new \ReflectionMethod($subcmd, 'addCommandArgument');
60
        $rmeth->setAccessible(true);
61
        $rmeth->invoke($subcmd, $argOne);
62
63
        $rmeth = new \ReflectionMethod($subcmd, 'addCommandArgument');
64
        $rmeth->setAccessible(true);
65
        $rmeth->invoke($subcmd, [$argTwo, $argTwoValue]);
66
67
        $actual = $subcmd->getCommand();
68
        $this->assertEquals(
69
            $expected,
70
            $actual,
71
            'getCommand() produces string made from subject stact and extracted args'
72
        );
73
    }
74
}
75