Passed
Push — unit ( fc9abb...3cd14f )
by Luke
02:42
created

GitVersionControlTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 1
cbo 3
dl 0
loc 32
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testCreateProcess() 0 7 1
A testRunCommand() 0 10 1
A testRunCommandThrows() 0 11 1
1
<?php
2
3
/**
4
 * Moodle component manager.
5
 *
6
 * @author Luke Carrier <[email protected]>
7
 * @copyright 2016 Luke Carrier
8
 * @license GPL-3.0+
9
 */
10
11
namespace ComponentManager\Test\VersionControl\Git;
12
13
use ComponentManager\Exception\VersionControlException;
14
use ComponentManager\VersionControl\Git\Command\Command;
15
use ComponentManager\VersionControl\Git\GitVersionControl;
16
use PHPUnit\Framework\TestCase;
17
use Symfony\Component\Process\Process;
18
19
/**
20
 * @coversDefaultClass \ComponentManager\VersionControl\GitVersionControl
21
 */
22
class GitVersionControlTest extends TestCase {
23
    public function testCreateProcess() {
24
        $repo = new GitVersionControl('git', getcwd());
25
        $process = $repo->createProcess(['help']);
26
27
        $this->assertEquals(getcwd(), $process->getWorkingDirectory());
28
        $this->assertEquals('\'git\' \'help\'', $process->getCommandLine());
29
    }
30
31
    public function testRunCommand() {
32
        $repo = new GitVersionControl('git', getcwd());
33
        $command = $this->createMock(Command::class);
34
        $command->method('getCommandLine')
35
            ->willReturn(['help']);
36
        $process = $repo->runCommand($command);
37
38
        $this->assertInstanceOf(Process::class, $process);
39
        $this->assertEquals(0, $process->getExitCode());
40
    }
41
42
    public function testRunCommandThrows() {
43
        $repo = new GitVersionControl('git', 'getcwd');
44
        $command = $this->createMock(Command::class);
45
        $command->method('getCommandLine')
46
            ->willReturn(['completely-invalid-command']);
47
48
        $this->expectException(VersionControlException::class);
49
        $this->expectExceptionCode(999);
50
51
        $repo->runCommand($command, 999);
52
    }
53
}
54