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

PrePushTest::testRunHookEnabledNoActions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 13
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 17
rs 9.8333
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\Runner\Hook;
13
14
use CaptainHook\App\Config\Mockery as ConfigMockery;
15
use CaptainHook\App\Console\IO\Mockery as IOMockery;
16
use CaptainHook\App\Git\DummyRepo;
17
use CaptainHook\App\Mockery as CHMockery;
18
use PHPUnit\Framework\TestCase;
19
20
class PrePushTest extends TestCase
21
{
22
    use ConfigMockery;
23
    use IOMockery;
24
    use CHMockery;
25
26
    /**
27
     * Tests PrePush::run
28
     *
29
     * @throws \Exception
30
     */
31
    public function testRunHookEnabled(): void
32
    {
33
        $dummy = new DummyRepo(['hooks' => ['pre-push' => '# hook script']]);
34
        $repo  = $this->createRepositoryMock($dummy->getRoot());
35
        $repo->method('getHooksDir')->willReturn($dummy->getHookDir());
36
37
        $io           = $this->createIOMock();
38
        $config       = $this->createConfigMock();
39
        $hookConfig   = $this->createHookConfigMock();
40
        $actionConfig = $this->createActionConfigMock();
41
        $hookConfig->method('isEnabled')->willReturn(true);
42
        $hookConfig->expects($this->once())->method('getActions')->willReturn([$actionConfig]);
43
        $config->expects($this->once())->method('getHookConfigToExecute')->willReturn($hookConfig);
44
        $config->expects($this->atLeastOnce())->method('isHookEnabled')->willReturn(true);
45
        $io->expects($this->atLeast(1))->method('write');
46
47
        $runner = new PrePush($io, $config, $repo);
48
        $runner->run();
49
    }
50
51
    /**
52
     * Tests PrePush::run
53
     *
54
     * @throws \Exception
55
     */
56
    public function testRunHookEnabledNoActions(): void
57
    {
58
        $dummy = new DummyRepo(['hooks' => ['pre-push' => '# hook script']]);
59
        $repo  = $this->createRepositoryMock($dummy->getRoot());
60
        $repo->method('getHooksDir')->willReturn($dummy->getHookDir());
61
62
        $io         = $this->createIOMock();
63
        $config     = $this->createConfigMock();
64
        $hookConfig = $this->createHookConfigMock();
65
        $hookConfig->method('isEnabled')->willReturn(true);
66
        $hookConfig->expects($this->once())->method('getActions')->willReturn([]);
67
        $config->expects($this->once())->method('getHookConfigToExecute')->willReturn($hookConfig);
68
        $config->expects($this->atLeastOnce())->method('isHookEnabled')->willReturn(true);
69
        $io->expects($this->atLeast(1))->method('write');
70
71
        $runner = new PrePush($io, $config, $repo);
72
        $runner->run();
73
    }
74
75
    /**
76
     * Tests PrePush::run
77
     *
78
     * @throws \Exception
79
     */
80
    public function testRunHookDisabled(): void
81
    {
82
        $io           = $this->createIOMock();
83
        $config       = $this->createConfigMock();
84
        $repo         = $this->createRepositoryMock();
85
        $config->expects($this->atLeastOnce())->method('isHookEnabled')->willReturn(false);
86
        $io->expects($this->atLeast(1))->method('write');
87
88
        $runner = new PrePush($io, $config, $repo);
89
        $runner->run();
90
    }
91
}
92