UninstallTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 22
dl 0
loc 41
rs 10
c 1
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testUninstallPreCommitHook() 0 22 1
A testFailMissingConfig() 0 15 1
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;
20
use Symfony\Component\Console\Input\ArrayInput;
21
use Symfony\Component\Console\Output\NullOutput;
22
23
class UninstallTest extends TestCase
24
{
25
    public function testFailMissingConfig(): void
26
    {
27
        $output = new NullOutput();
28
        $input  = new ArrayInput(
29
            [
30
                'hook'            => 'pre-commit',
31
                '--configuration' => 'foo',
32
                '--git-directory' => 'bar'
33
            ]
34
        );
35
36
        $install = new Uninstall(new Resolver(CH_PATH_FILES . '/bin/captainhook'));
37
        $code    = $install->run($input, $output);
38
39
        $this->assertEquals(1, $code);
40
    }
41
42
    public function testUninstallPreCommitHook(): void
43
    {
44
        $repo   = new DummyRepo([
45
            'config' => '# fake git config',
46
            'hooks'  => [
47
                'pre-commit' => '# fake pre-commit hook file',
48
                'pre-push'   => '# fake pre-push hook file',
49
            ]
50
        ]);
51
        $output = new NullOutput();
52
        $input  = new ArrayInput(
53
            [
54
                'hook'            => 'pre-commit',
55
                '--git-directory' => $repo->getGitDir(),
56
                '--configuration' => CH_PATH_FILES . '/config/valid.json'
57
            ]
58
        );
59
60
        $install = new Uninstall(new Resolver(CH_PATH_FILES . '/bin/captainhook'));
61
        $install->run($input, $output);
62
63
        $this->assertFalse($repo->hookExists('pre-commit'));
64
    }
65
}
66