Passed
Push — main ( f0911f...cd99fe )
by Sebastian
05:24
created

HooksTest::testAllowsUserInput()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
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;
13
14
use Exception;
15
use PHPUnit\Framework\TestCase;
16
17
class HooksTest extends TestCase
18
{
19
    /**
20
     * Tests Hooks::getOriginalHookArguments
21
     */
22
    public function testHookArguments(): void
23
    {
24
        $this->assertEquals('', Hooks::getOriginalHookArguments('pre-commit'));
25
        $this->assertEquals(' {$PREVIOUSHEAD} {$NEWHEAD} {$MODE}', Hooks::getOriginalHookArguments('post-checkout'));
26
    }
27
28
    /**
29
     * Tests Hooks::getVirtualHook
30
     */
31
    public function testGetVirtualHook(): void
32
    {
33
        $this->assertEquals('post-change', Hooks::getVirtualHook('post-rewrite'));
34
    }
35
36
    /**
37
     * Tests Hooks::getNativeHooksForVirtualHook
38
     */
39
    public function testGetNativeHooksForVirtualHookWithVirtual(): void
40
    {
41
        $hooks = Hooks::getNativeHooksForVirtualHook(Hooks::POST_CHANGE);
42
43
        $this->assertTrue(in_array(Hooks::POST_CHECKOUT, $hooks));
44
        $this->assertTrue(in_array(Hooks::POST_MERGE, $hooks));
45
        $this->assertTrue(in_array(Hooks::POST_REWRITE, $hooks));
46
    }
47
48
    /**
49
     * Tests Hooks::getNativeHooksForVirtualHook
50
     */
51
    public function testGetNativeHooksForVirtualHookWithNative(): void
52
    {
53
        $hooks = Hooks::getNativeHooksForVirtualHook(Hooks::PRE_COMMIT);
54
55
        $this->assertTrue(empty($hooks));
56
    }
57
58
    /**
59
     * Tests Hooks::getVirtualHook
60
     */
61
    public function testGetVirtualHookFail(): void
62
    {
63
        $this->expectException(Exception::class);
64
        Hooks::getVirtualHook('pre-commit');
65
    }
66
67
    public function testReceivesStdIn(): void
68
    {
69
        $this->assertTrue(Hooks::receivesStdIn(Hooks::PRE_PUSH));
70
        $this->assertTrue(Hooks::receivesStdIn(Hooks::POST_REWRITE));
71
        $this->assertFalse(Hooks::receivesStdIn(Hooks::PRE_COMMIT));
72
    }
73
}
74