|
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('float', $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(); |
|
|
|
|
|
|
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())); |
|
|
|
|
|
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* @expectedException \GitElephant\Exception\InvalidRepositoryPathException |
|
124
|
|
|
*/ |
|
125
|
|
|
public function testRepositoryValidation() |
|
126
|
|
|
{ |
|
127
|
|
|
$binary = new GitBinary(); |
|
128
|
|
|
$caller = new Caller($binary, 'someinvalidpath'); |
|
|
|
|
|
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.