GitVersionControlTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 30.43 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 14
loc 46
rs 10
c 1
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testCreateProcessLinux() 7 7 1
A testCreateProcessWindows() 7 7 1
A testRunCommand() 0 10 1
A testRunCommandThrows() 0 11 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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