GitVersionControlTest::testCreateProcessLinux()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 7
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 7
loc 7
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
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
    /**
24
     * @group platform-linux
25
     */
26 View Code Duplication
    public function testCreateProcessLinux() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
27
        $repo = new GitVersionControl('git', getcwd());
28
        $process = $repo->createProcess(['help']);
29
30
        $this->assertEquals(getcwd(), $process->getWorkingDirectory());
31
        $this->assertEquals('\'git\' \'help\'', $process->getCommandLine());
32
    }
33
34
    /**
35
     * @group platform-windows
36
     */
37 View Code Duplication
    public function testCreateProcessWindows() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
38
        $repo = new GitVersionControl('git', getcwd());
39
        $process = $repo->createProcess(['help']);
40
41
        $this->assertEquals(getcwd(), $process->getWorkingDirectory());
42
        $this->assertEquals('git help', $process->getCommandLine());
43
    }
44
45
    public function testRunCommand() {
46
        $repo = new GitVersionControl('git', getcwd());
47
        $command = $this->createMock(Command::class);
48
        $command->method('getCommandLine')
49
            ->willReturn(['help']);
50
        $process = $repo->runCommand($command);
51
52
        $this->assertInstanceOf(Process::class, $process);
53
        $this->assertEquals(0, $process->getExitCode());
54
    }
55
56
    public function testRunCommandThrows() {
57
        $repo = new GitVersionControl('git', getcwd());
58
        $command = $this->createMock(Command::class);
59
        $command->method('getCommandLine')
60
            ->willReturn(['completely-invalid-command']);
61
62
        $this->expectException(VersionControlException::class);
63
        $this->expectExceptionCode(999);
64
65
        $repo->runCommand($command, 999);
66
    }
67
}
68