Passed
Push — master ( b89ee9...82ea21 )
by Sebastian
03:18
created

InstallTest::testExecutePreCommit()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 26
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 26
rs 9.7998
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
/**
4
 * This file is part of CaptainHook
5
 *
6
 * (c) Sebastian Feldmann <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace CaptainHook\App\Console\Command;
13
14
use CaptainHook\App\Console\IO\NullIO;
15
use CaptainHook\App\Console\Runtime\Resolver;
16
use CaptainHook\App\Git\DummyRepo;
17
use CaptainHook\App\Hook\Template;
18
use Exception;
19
use PHPUnit\Framework\TestCase;
1 ignored issue
show
Bug introduced by
The type PHPUnit\Framework\TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
20
use Symfony\Component\Console\Input\ArrayInput;
21
use Symfony\Component\Console\Output\NullOutput;
22
23
class InstallTest extends TestCase
24
{
25
    /**
26
     * Tests Install::run
27
     *
28
     * @throws \Exception
29
     */
30
    public function testFailMissingConfig(): void
31
    {
32
        $this->expectException(Exception::class);
33
34
        $output = new NullOutput();
35
        $input  = new ArrayInput(
36
            [
37
                'hook'            => 'pre-commit',
38
                '--configuration' => 'foo',
39
                '--git-directory' => 'bar'
40
            ]
41
        );
42
43
        $install = new Install(new Resolver(), CH_PATH_FILES . '/bin/captainhook');
44
        $install->run($input, $output);
45
    }
46
47
    /**
48
     * Tests Install::run
49
     *
50
     * @throws \Exception
51
     */
52
    public function testFailInvalidRepository(): void
53
    {
54
        $this->expectException(Exception::class);
55
56
        $output = new NullOutput();
57
        $input  = new ArrayInput(
58
            [
59
                'hook'            => 'pre-commit',
60
                '--configuration' => CH_PATH_FILES . '/config/valid.json',
61
                '--git-directory' => 'bar/.git'
62
            ]
63
        );
64
65
        $install = new Install(new Resolver(), CH_PATH_FILES . '/bin/captainhook');
66
        $install->setIO(new NullIO());
67
        $install->run($input, $output);
68
    }
69
70
    /**
71
     * Tests Install::run
72
     *
73
     * @throws \Exception
74
     */
75
    public function testFailMissingRunExecOption(): void
76
    {
77
        $this->expectException(Exception::class);
78
79
        $repo   = new DummyRepo();
80
        $output = new NullOutput();
81
        $input  = new ArrayInput(
82
            [
83
                'hook'            => 'pre-commit',
84
                '--configuration' => CH_PATH_FILES . '/template/captainhook.json',
85
                '--git-directory' => $repo->getGitDir(),
86
                '--run-mode'      => Template::DOCKER
87
            ]
88
        );
89
90
        $install = new Install(new Resolver(), CH_PATH_FILES . '/bin/captainhook');
91
        $install->run($input, $output);
92
    }
93
94
95
    /**
96
     * Tests Install::run
97
     *
98
     * @throws \Exception
99
     */
100
    public function testInstallPreCommitHook(): void
101
    {
102
        $repo   = new DummyRepo();
103
        $output = new NullOutput();
104
        $input  = new ArrayInput(
105
            [
106
                'hook'            => 'pre-commit',
107
                '--configuration' => CH_PATH_FILES . '/template/captainhook.json',
108
                '--git-directory' => $repo->getGitDir()
109
            ]
110
        );
111
112
        $install = new Install(new Resolver(), CH_PATH_FILES . '/bin/captainhook');
113
        $install->run($input, $output);
114
115
        $this->assertTrue($repo->hookExists('pre-commit'));
116
    }
117
}
118