Passed
Push — master ( 21c505...12ca40 )
by Sebastian
02:34
created

InstallTest::testExecutePreCommit()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 27
c 0
b 0
f 0
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 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
    public function testExecuteInvalidRepository()
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