CallerTest::testGetOutput()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

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