Completed
Pull Request — develop (#147)
by
unknown
02:05
created

CallerTest::testGetBinaryVersion()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
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\TestCase;
17
use \GitElephant\Command\Caller\Caller;
18
use \GitElephant\GitBinary;
19
use \GitElephant\Command\MainCommand;
20
21
/**
22
 * CallerTest
23
 *
24
 * @author Matteo Giachino <[email protected]>
25
 */
26
class CallerTest extends TestCase
27
{
28
    /**
29
     * setUp
30
     */
31
    public function setUp()
32
    {
33
        $this->initRepository();
34
    }
35
36
    /**
37
     * @covers GitElephant\Command\Caller\Caller::__construct
38
     */
39
    public function testConstructor()
40
    {
41
        $binary = new GitBinary();
42
        $caller = new Caller($binary, $this->getRepository()->getPath());
43
        $this->assertNotEmpty($caller->execute('--version'));
44
    }
45
46
    /**
47
     * testGetBinaryPath
48
     */
49
    public function testGetBinaryPath()
50
    {
51
        $binary = new GitBinary();
52
        $c = new Caller($binary, $this->repository->getPath());
53
        $this->assertEquals(exec('which git'), $c->getBinaryPath());
54
    }
55
56
    /**
57
     * testGetBinaryVersion
58
     */
59
    public function testGetBinaryVersion()
60
    {
61
        $binary = new GitBinary();
62
        $c = new Caller($binary, $this->repository->getPath());
63
        $this->assertInternalType('string', $c->getBinaryVersion());
64
    }
65
66
    /**
67
     * @expectedException \RuntimeException
68
     */
69
    public function testGetError()
70
    {
71
        $binary = new GitBinary();
72
        $caller = new Caller($binary, $this->getRepository()->getPath());
73
        $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...
74
        $caller->execute('foo');
75
    }
76
77
    /**
78
     * get output test
79
     */
80
    public function testGetOutput()
81
    {
82
        $binary = new GitBinary();
83
        $caller = new Caller($binary, $this->getRepository()->getPath());
84
        $mainCommand = new MainCommand();
85
        $caller->execute($mainCommand->init());
86
        $this->assertRegExp(
87
            sprintf('/^(.*)%s/', str_replace('/', '\/', $this->getRepository()->getPath())),
88
            $caller->getOutput()
89
        );
90
    }
91
92
    /**
93
     * testOutputLines
94
     */
95
    public function testOutputLines()
96
    {
97
        $binary = new GitBinary();
98
        $caller = new Caller($binary, $this->getRepository()->getPath());
99
        $this->getRepository()->init();
100
        for ($i = 1; $i <= 50; $i++) {
101
            $this->addFile('test'.$i, null, 'this is the content');
102
        }
103
        $this->getRepository()->commit('first commit', true);
104
        $command = new LsTreeCommand();
105
        $outputLines = $caller->execute($command->fullTree($this->getRepository()->getMainBranch()))->getOutputLines();
106
        $this->assertTrue(is_array($outputLines));
107
        $this->assertEquals(range(0, count($outputLines) - 1), array_keys($outputLines));
108
    }
109
110
    /**
111
     * testGetRawOutput
112
     */
113
    public function testGetRawOutput()
114
    {
115
        $binary = new GitBinary();
116
        $this->getRepository()->init();
117
        $caller = new Caller($binary, $this->getRepository()->getPath());
118
        $caller->execute('status');
119
        $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...
120
    }
121
122
    /**
123
     * @expectedException \GitElephant\Exception\InvalidRepositoryPathException
124
     */
125
    public function testRepositoryValidation()
126
    {
127
        $binary = new GitBinary();
128
        $caller = new Caller($binary, '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...
129
    }
130
}
131