Passed
Push — master ( b34030...56c38f )
by Sebastian
03:50
created

InstallTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 75
Duplicated Lines 20 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 5
dl 15
loc 75
c 0
b 0
f 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testExecuteNoConfig() 0 14 1
A testExecuteInvalidRepository() 15 15 1
B testExecutePreCommit() 0 27 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
 * This file is part of CaptainHook.
4
 *
5
 * (c) Sebastian Feldmann <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace sebastianfeldmann\CaptainHook\Console\Command;
11
12
use sebastianfeldmann\CaptainHook\Console\IO\NullIO;
13
use sebastianfeldmann\CaptainHook\Git\DummyRepo;
14
use Symfony\Component\Console\Input\ArrayInput;
15
use Symfony\Component\Console\Tests\Fixtures\DummyOutput;
16
17
class InstallTest extends \PHPUnit_Framework_TestCase
18
{
19
    /**
20
     * Tests Install::run
21
     *
22
     * @expectedException \Exception
23
     */
24
    public function testExecuteNoConfig()
25
    {
26
        $input   = new ArrayInput(
27
            [
28
                'hook' => 'pre-commit',
29
                '--configuration' => 'foo',
30
                '--git-directory' => 'bar'
31
            ]
32
        );
33
        $output  = new DummyOutput();
34
        $install = new Install();
35
        $install->setIO(new NullIO());
36
        $install->run($input, $output);
37
    }
38
39
    /**
40
     * Tests Install::run
41
     *
42
     * @expectedException \Exception
43
     */
44 View Code Duplication
    public function testExecuteInvalidRepository()
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...
45
    {
46
        $input   = new ArrayInput(
47
            [
48
                'hook' => 'pre-commit',
49
                '--configuration' => HMU_PATH_FILES . '/config/valid.json',
50
                '--git-directory' => 'bar/.git'
51
            ]
52
        );
53
54
        $output  = new DummyOutput();
55
        $install = new Install();
56
        $install->setIO(new NullIO());
57
        $install->run($input, $output);
58
    }
59
60
61
    /**
62
     * Tests Install::run
63
     */
64
    public function testExecutePreCommit()
65
    {
66
        $repo = new DummyRepo();
67
        $repo->setup();
68
69
        $install = new Install();
70
        $output  = new DummyOutput();
71
        $input   = new ArrayInput(
72
            [
73
                'hook' => 'pre-commit',
74
                '--configuration' => HMU_PATH_FILES . '/config/valid.json',
75
                '--git-directory' => $repo->getGitDir()
76
            ]
77
        );
78
79
        $install->setIO(new NullIO());
80
        $install->run($input, $output);
81
82
        // make sure the file is installed
83
        $this->assertTrue(
84
            file_exists(
85
                $repo->getGitDir() . DIRECTORY_SEPARATOR . 'hooks' . DIRECTORY_SEPARATOR . 'pre-commit'
86
            )
87
        );
88
89
        $repo->cleanup();
90
    }
91
}
92