Passed
Push — master ( 7bee4d...457c92 )
by Sebastian
01:54
created

HookTest::testRunInvalidHook()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
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\Application;
11
12
use CaptainHook\App\CH;
13
use CaptainHook\App\Config;
14
use CaptainHook\App\Git\DummyRepo;
15
use Symfony\Component\Console\Input\ArrayInput;
16
use Symfony\Component\Console\Output\NullOutput;
17
use PHPUnit\Framework\TestCase;
18
19
class HookTest extends TestCase
20
{
21
    /**
22
     * Tests Hook::run
23
     */
24
    public function testRun(): void
25
    {
26
        if (\defined('PHP_WINDOWS_VERSION_MAJOR')) {
27
            $this->markTestSkipped('not tested on windows');
28
        }
29
30
        $config = new Config(CH_PATH_FILES . '/config/valid.json');
31
        $repo   = new DummyRepo();
32
        $output = new NullOutput();
33
        $input  = new ArrayInput([
34
            'file' => CH_PATH_FILES . '/git/message/valid.txt',
35
        ]);
36
        $app = new Hook();
37
        $app->setConfigFile($config->getPath());
38
        $app->setRepositoryPath($repo->getPath());
39
        $app->setHook('commit-msg');
40
        $app->setAutoExit(false);
41
        $app->run($input, $output);
42
43
        $repo->cleanup();
44
45
        $this->assertTrue(true);
46
    }
47
48
    /**
49
     * Tests Hook::executeHook
50
     */
51
    public function testRunInvalidHook(): void
52
    {
53
        $this->expectException(\Exception::class);
54
55
        $app = new Hook();
56
        $app->setHook('pre-foo');
57
    }
58
59
    /**
60
     * Tests Hook::executeHook
61
     */
62
    public function testRunNoHook(): void
63
    {
64
        $input  = new ArrayInput([]);
65
        $output = new NullOutput();
66
        $app    = new Hook();
67
        $app->setAutoExit(false);
68
        $exit = $app->run($input, $output);
69
70
        $this->assertTrue($exit !== 0);
71
    }
72
73
    /**
74
     * Tests Hook::getRepositoryPath
75
     */
76
    public function testGetRepositoryPath(): void
77
    {
78
        $app = new Hook();
79
80
        $this->assertEquals(getcwd(), $app->getRepositoryPath());
81
    }
82
83
    /**
84
     * Tests Hook::getConfigFile
85
     */
86
    public function testGetConfigFile(): void
87
    {
88
        $app = new Hook();
89
90
        $this->assertEquals(getcwd()  . DIRECTORY_SEPARATOR . CH::CONFIG, $app->getConfigFile());
91
    }
92
93
    /**
94
     * Tests Application::getHelp
95
     */
96
    public function testGetHelp(): void
97
    {
98
        $hook = new Hook();
99
        $help = $hook->getHelp();
100
101
        $this->assertStringContainsString('$$$$b ^ceeeee.  4$$ECL.F*$$$$$$$', $help);
102
    }
103
}
104