Completed
Push — develop ( 61d4f1...4b8b90 )
by
unknown
9s
created

CallerTest::testGetBinaryVersion()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
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\Command\Caller\Caller;
17
use \GitElephant\Command\MainCommand;
18
use \GitElephant\TestCase;
19
20
/**
21
 * CallerTest
22
 *
23
 * @author Matteo Giachino <[email protected]>
24
 */
25
class CallerTest extends TestCase
26
{
27
    /**
28
     * setUp
29
     */
30
    public function setUp()
31
    {
32
        $this->initRepository();
33
    }
34
35
    /**
36
     * @covers GitElephant\Command\Caller\Caller::__construct
37
     */
38
    public function testConstructor()
39
    {
40
        $caller = new Caller(null, $this->getRepository()->getPath());
41
        $this->assertNotEmpty($caller->execute('--version'));
42
    }
43
44
    /**
45
     * testGetBinaryPath
46
     */
47
    public function testGetBinaryPath()
48
    {
49
        $c = new Caller(null, $this->repository->getPath());
50
        $this->assertEquals(exec('which git'), $c->getBinaryPath());
51
    }
52
53
    /**
54
     * testGetBinaryVersion
55
     */
56
    public function testGetBinaryVersion()
57
    {
58
        $c = new Caller(null, $this->repository->getPath());
59
        $this->assertInternalType('string', $c->getBinaryVersion());
60
    }
61
62
    /**
63
     * @expectedException \RuntimeException
64
     */
65
    public function testGetError()
66
    {
67
        $binary = null;
0 ignored issues
show
Unused Code introduced by
$binary is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
68
        $caller = new Caller(null, $this->getRepository()->getPath());
69
        $mainCommand = new MainCommand();
0 ignored issues
show
Unused Code introduced by
$mainCommand is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
70
        $caller->execute('foo');
71
    }
72
73
    /**
74
     * get output test
75
     */
76
    public function testGetOutput()
77
    {
78
        $caller = new Caller(null, $this->getRepository()->getPath());
79
        $mainCommand = new MainCommand();
80
        $caller->execute($mainCommand->init());
81
        $this->assertRegExp(
82
            sprintf('/^(.*)%s/', str_replace('/', '\/', $this->getRepository()->getPath())),
83
            $caller->getOutput()
84
        );
85
    }
86
87
    /**
88
     * testOutputLines
89
     */
90
    public function testOutputLines()
91
    {
92
        $caller = new Caller(null, $this->getRepository()->getPath());
93
        $this->getRepository()->init();
94
        for ($i = 1; $i <= 50; $i++) {
95
            $this->addFile('test' . $i, null, 'this is the content');
96
        }
97
        $this->getRepository()->commit('first commit', true);
98
        $command = new LsTreeCommand();
99
        $outputLines = $caller->execute($command->fullTree($this->getRepository()->getMainBranch()))->getOutputLines();
100
        $this->assertTrue(is_array($outputLines));
101
        $this->assertEquals(range(0, count($outputLines) - 1), array_keys($outputLines));
102
    }
103
104
    /**
105
     * testGetRawOutput
106
     */
107
    public function testGetRawOutput()
108
    {
109
        $this->getRepository()->init();
110
        $caller = new Caller(null, $this->getRepository()->getPath());
111
        $caller->execute('status');
112
        $this->assertRegExp('/master/', $caller->getRawOutput($caller->getRawOutput()));
0 ignored issues
show
Unused Code introduced by
The call to Caller::getRawOutput() has too many arguments starting with $caller->getRawOutput().

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
113
    }
114
115
    /**
116
     * @expectedException \GitElephant\Exception\InvalidRepositoryPathException
117
     */
118
    public function testRepositoryValidation()
119
    {
120
        $caller = new Caller(null, 'someinvalidpath');
0 ignored issues
show
Unused Code introduced by
$caller is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
121
    }
122
}
123