Passed
Push — master ( 813fe9...62056b )
by Sebastian
06:01
created

InstallTest::testExecutePreCommit()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 27
rs 8.8571
cc 1
eloc 15
nc 1
nop 0
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 CaptainHook\App\Console\Command;
11
12
use CaptainHook\App\Console\IO\NullIO;
13
use CaptainHook\App\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